Delete a file or a directory
349982
def action_create(self, courseid, taskid, path):
        
        # the path is given by the user. Let's normalize it
        path = path.strip()
        if not path.startswith("/"):
            path = "/" + path

        want_directory = path.endswith("/")

        wanted_path = self.verify_path(courseid, taskid, path, True)
        if wanted_path is None:
            return self.show_tab_file(courseid, taskid, _("Invalid new path"))

        task_fs = self.task_factory.get_task_fs(courseid, taskid)
        if want_directory:
            task_fs.from_subfolder(wanted_path).ensure_exists()
        else:
            task_fs.put(wanted_path, b"")
        return self.show_tab_file(courseid, taskid)
1289093
def clean(cls, path):
        ''''''
        for pth in os.listdir(path):
            pth = os.path.abspath(os.path.join(path, pth))
            if os.path.isdir(pth):
                logger.debug('Removing directory %s' % pth)
                shutil.rmtree(pth)
            else:
                logger.debug('Removing file %s' % pth)
                os.remove(pth)
1177880
def remove(path):
    
    if os.path.isdir(path):
        return __rmtree(path)
    else:
        return __rmfile(path)
66962
def _clean_directory(self, name):
        """"""
        if not os.path.exists(name):
            return
        self.announce(
            "removing directory '{}' and all its contents".format(name)
        )
        if not self.dry_run:
            rmtree(name, True)
1087594
def delete_directories(paths):
    
    for path in paths:
        if os.path.exists(path):
            shutil.rmtree(path)
594045
def delete_config_dir
      begin
        FileUtils.rm_r(config_dir) if dir_exists?

      rescue StandardError => e
        raise FileAccessError, e.message
      end
    end
667257
def delete(self, *args, **kwargs):
        
        try:
            os.remove(self.file.file.name)
        # image does not exist
        except (OSError, IOError):
            pass
        super(Image, self).delete(*args, **kwargs)
798549
def _delete_dir(self):
        
        if not self.auto and os.path.isdir(self.meta.build_path + self.prgnam):
            shutil.rmtree(self.meta.build_path + self.prgnam)
987544
def delete(self):
        
        fs, path = self._get_fs(create_dir=False)
        if fs.exists(path):
            fs.remove(path)
        if self.clean_dir and fs.exists('.'):
            fs.removedir('.')
        return True
565693
def do_rm(self, path):
        path = path[0]

        """"""
        self.n.delete(self.current_path + path)
        self.dirs = self.dir_complete()
        self.files = self.file_complete()
933809
def remove_dir(path)
      if File.directory?(path)
        Dir.foreach(path) do |file|
          if ((file.to_s != ".") && (file.to_s != ".."))
            remove_dir("#{path}/#{file}")
          end
        end
        Dir.delete(path)
      else
        File.delete(path)
      end
    end
1284439
private function rm($dir_or_file){
		if( is_dir($dir_or_file) ){
			foreach( scandir($dir_or_file) as $file ){
				if( false === array_search($file, ['.', '..']) ){
					$this->rm( rtrim($dir_or_file, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file );
				}
			}
			if( !rmdir($dir_or_file) ){
				throw new \Exception(sprintf('Failed to delete %s. Please check permission', $dir_or_file), 403);
			}
		}elseif( is_file($dir_or_file) ){
			if( !unlink($dir_or_file) ){
				throw new \Exception(sprintf('Failed to delete %s. Please check permission', $dir_or_file), 403);
			}
		}else{
			throw new \Exception(sprintf('%s is not file or directory.', $dir_or_file), 404);
		}
	}
34736
def clean():
    
    for dirpath, dirnames, filenames in os.walk('.'):
        for filename in filenames:
            if filename.endswith('.pyc') or filename.endswith('.pyo'):
                filepath = os.path.join(dirpath, filename)
                click.echo(f'Removing {filepath}')
                os.remove(filepath)
1684
def delete(self):
        """"""
        if self.isfile:
            os.remove(self.fn)
        elif self.isdir:
            shutil.rmtree(self.fn)
843968
def clean(verbose=False):
    
    def rm(name):
        if os.path.isfile(name):
            os.remove(name)
            if verbose:
                printer.info('Removed file:', name)
        else:
            if verbose:
                printer.info('File not present:', name)

    def rmdir(name):
        if os.path.isdir(name):
            shutil.rmtree(name)
            if verbose:
                printer.info('Removed directory:', name)
        else:
            if verbose:
                printer.info('Directory not present:', name)

    root = os.getcwd()

    rmdir('build')
    rmdir('dist')

    for path, dirs, files in os.walk(root):
        rel_path = os.path.relpath(path, root)

        if rel_path == '.':
            rel_path = ''

        if rel_path.startswith('.'):
            continue

        for d in dirs:
            if d == '__pycache__':
                rmdir(os.path.join(rel_path, d))

        for f in files:
            if f.endswith('.pyc') or f.endswith('.pyo'):
                rm(os.path.join(rel_path, f))
1331015
def delete_file(self, path, prefixed_path, source_storage):
        
        if self.faster:
            return True
        else:
            return super(Command, self).delete_file(path, prefixed_path, source_storage)
769476
private synchronized static void delete(File file) {
        // Check if file is directory
        if (file.isDirectory()) {
            // Get all files in the folder
            File[] files = file.listFiles();

            // Delete each file in the folder
            for (int i = 0; i < files.length; ++i) {
                delete(files[i]);
            }

            // Delete the folder
            file.delete();
        } else {
            // Delete the file if it is not a folder
            file.delete();
        }
    }