I’ve always had a lot of troubles when it comes to delete folders on SublimeText (windows), that command is not reliable at all, I always end up opening a windows explorer and deleting the folders from there. I know this is not new topic, I’ve already read some old threads asking about this issue but didn’t see any solution so far and this issue hasn’t been addressed for years so let me bring it back again.
Here’s the thing, there is this little delete_folder command living in side_bar.py:
class DeleteFolderCommand(sublime_plugin.WindowCommand):
def run(self, dirs):
if len(dirs) == 1:
message = "Delete Folder %s?" % dirs[0]
else:
message = "Delete %d Folders?" % len(dirs)
if sublime.ok_cancel_dialog(message, "Delete"):
import Default.send2trash as send2trash
try:
for d in dirs:
send2trash.send2trash(d)
except Exception as e:
import traceback
traceback.print_exc()
sublime.status_message("Unable to delete folder")
def is_visible(self, dirs):
return len(dirs) > 0
which uses send2trash library, if we look at the windows relevant bits of send2trash the relevant bits are:
def send2trash(path):
# if not isinstance(path, str):
# path = str(path, 'mbcs')
if not op.isabs(path):
path = op.abspath(path)
fileop = SHFILEOPSTRUCTW()
fileop.hwnd = 0
fileop.wFunc = FO_DELETE
fileop.pFrom = LPCWSTR(path + '\0')
fileop.pTo = None
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT
fileop.fAnyOperationsAborted = 0
fileop.hNameMappings = 0
fileop.lpszProgressTitle = None
result = SHFileOperationW(byref(fileop))
if result:
msg = "Couldn't perform operation. Error code: %d" % result
raise OSError(msg)
Here’s some of the tracebacks I’ve got very often when trying to delete a folder:
Traceback (most recent call last):
File "D:\sources\personal\sublimetext3\Data\Packages\Default\side_bar.py", line 57, in run
send2trash.send2trash(d)
File "D:\sources\personal\sublimetext3\Packages\Default.sublime-package\send2trash/plat_win.py", line 54, in send2trash
raise OSError(msg)
OSError: Couldn't perform operation. Error code: 124
or:
Unable to open /D/sources/personal/sublimetext3/Data/Packages/Default/send2trash/plat_win.py
Traceback (most recent call last):
File "D:\sources\personal\sublimetext3\Data\Packages\Default\side_bar.py", line 57, in run
send2trash.send2trash(d)
File "D:\sources\personal\sublimetext3\Packages\Default.sublime-package\send2trash/plat_win.py", line 54, in send2trash
raise OSError(msg)
OSError: Couldn't perform operation. Error code: 120
By looking at the docs I see those error codes mean:
DE_ACCESSDENIEDSRC 0x78 Security settings denied access to the source.
DE_INVALIDFILES 0x7C The path in the source or destination or both was invalid.
Is there any way to fix the code to overcome these errors?
I said “fix” the code cos whether a folder can be deleted from windows explorer but not inside SublimeText that’s a bug. And this is quite a common operation so…
Thanks in advance