How to use the send2trash.send2trash function in Send2Trash

To help you get started, we’ve selected a few Send2Trash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onicagroup / runway / integration_tests / test_parallelism / test_parallelism.py View on Github external
def clean(self):
        """Clean up fixture test directory."""
        file_types = ('*.yaml', '*.yml')
        templates = []
        for file_type in file_types:
            templates.extend(glob.glob(os.path.join(
                self.parallelism_test_dir,
                file_type
            )))
        for template in templates:
            if os.path.isfile(template):
                self.logger.debug('send2trash: "%s"', template)
                send2trash(template)
        folders = ['sampleapp.cfn']
        for folder in folders:
            folder_path = os.path.join(self.parallelism_test_dir, folder)
            if os.path.isdir(folder_path):
                self.logger.debug('send2trash: "%s"', folder_path)
                send2trash(folder_path)
github twiddli / happypanda / version / utils.py View on Github external
def delete_path(path):
    "Deletes the provided recursively"
    s = True
    if os.path.exists(path):
        error = ''
        if app_constants.SEND_FILES_TO_TRASH:
            try:
                send2trash.send2trash(path)
            except:
                log.exception("Unable to send file to trash")
                error = 'Unable to send file to trash'
        else:
            try:
                if os.path.isfile(path):
                    os.remove(path)
                else:
                    shutil.rmtree(path)
            except PermissionError:
                error = 'PermissionError'
            except FileNotFoundError:
                pass

        if error:
            p = os.path.split(path)[1]
github facelessuser / Rummage / rummage / lib / gui / dialogs / delete_dialog.py View on Github external
def retry(self):
        """Retry loop."""

        deleted = False
        self.request = True
        while self.trouble_file is not None and not self.abort:
            time.sleep(0.5)
            if self.response is not None:
                if self.response is True:
                    self.response = None
                    try:
                        if os.path.exists(self.trouble_file):
                            if self.recycle:
                                send2trash(self.trouble_file)
                            else:
                                os.remove(self.trouble_file)
                        deleted = True
                        self.trouble_file = None
                    except Exception:
                        self.request = True
                elif self.response is False:
                    self.response = None
                    self.trouble_file = None
        return deleted
github krichter722 / video-splitter / video_splitter / video_manager.py View on Github external
def onWorkingSetListPopupMenuItemDeleteClick(self, event):
        selected_indices = []
        next_selected = self.workingSetList.GetNextSelected(-1)
        while next_selected != -1:
            selected_indices.append(next_selected)
            next_selected = self.workingSetList.GetNextSelected(next_selected)
        for selected_index in selected_indices:
            next_selected_item = self.workingSetList.GetItem(selected_index, col=0)
            if next_selected_item.GetText() == self.trackPath:
                self.stopPlayback()
            logger.debug("moving '%s' to trash" % (next_selected_item.GetText(),))
            send2trash.send2trash(next_selected_item.GetText())
            self.workingSetList.DeleteItem(selected_index)
github xybu / onedrive-d-old / onedrive_d / od_worker_thread.py View on Github external
for ent_name in local_entries:
			# untouched local files
			local_path = task['local_path'] + '/' + ent_name
			if os.path.isdir(local_path):
				previous_entry = self.entrymgr.get_entry(isdir=True, local_path=local_path)
				if previous_entry is not None:
					if previous_entry['status'] == 'MOVED_TO':
						# the old record marks a movement
						# propagate to server
						self.taskmgr.add_task('mv', local_path, remote_id=previous_entry['remote_id'], remote_parent_id=previous_entry['remote_parent_id'])
					else:
						# there was an old record about this dir before
						# but now the dir in remote is gone
						try:
							send2trash(local_path)
							self.entrymgr.del_entry_by_parent(parent_path=local_path)
						except OSError as e:
							self.logger.error(e)
				else:
					# probably a dir that was newly created
					self.taskmgr.add_task(
						'mk', local_path, remote_parent_id=task['remote_id'], args='sy,recursive,')
			else:
				# we can pass local_entries during the iteration because the branch to run
				# in analyze_file_path will not modify local_entries.
				self.analyze_file_path(local_path, task['remote_id'], None, local_entries)

		self.taskmgr.del_task(task['task_id'])
github Shougo / defx.nvim / rplugin / python3 / defx / kind / file.py View on Github external
if not importlib.util.find_spec('send2trash'):
        error(view._vim, '"Send2Trash" is not installed')
        return

    force = context.args[0] == 'force' if context.args else False
    if not force:
        message = 'Are you sure you want to delete {}?'.format(
            str(context.targets[0]['action__path'])
            if len(context.targets) == 1
            else str(len(context.targets)) + ' files')
        if not confirm(view._vim, message):
            return

    import send2trash
    for target in context.targets:
        send2trash.send2trash(str(target['action__path']))
    view.redraw(True)
github xybu / onedrive-d-old / onedrive_d / od_worker_thread.py View on Github external
def remove_dir(self, task):
		if os.path.exists(task['local_path']) and os.path.isdir(task['local_path']):
			try:
				send2trash(task['local_path'])
			except OSError as e:
				self.logger.error(e)
		if not os.path.exists(task['local_path']):
			self.api.rm(task['remote_id'])
			self.entrymgr.del_entry_by_parent(task['local_path'])
		self.taskmgr.del_task(task['task_id'])
github titoBouzout / SideBarEnhancements / SideBar.py View on Github external
def run(self):
        paths = self.paths
        key = self.key
        window_set_status(key, "Emptying…")
        try:
            from .send2trash import send2trash

            for item in SideBarSelection(paths).getSelectedDirectoriesOrDirnames():
                for content in os.listdir(item.path()):
                    file = os.path.join(item.path(), content)
                    if not SideBarSelection().isNone(file):
                        send2trash(file)
                if s.get("close_affected_buffers_when_deleting_even_if_dirty", False):
                    item.closeViews()
        except:
            pass
        SideBarProject().refresh()
        window_set_status(key, "")
github rishooty / vrec-dat-filter / functions.py View on Github external
tree = ET.parse(clean_dat_file)
    root = tree.getroot()

    # Read in list of files
    files = os.listdir(rm_dir)

    # Extract all game names to a list
    files_to_keep = []
    for game in root.iter('game'):
            files_to_keep.append(game.get('name'))

    # If a file does not match any game names, delete it.
    print('Clearing '+rm_dir+'...')
    for file in files:
        if os.path.splitext(file)[0] not in files_to_keep:
            send2trash(rm_dir+file)
    print('Finished.')