2

I have (setq trash-directory "~/.Trash") and (setq delete-by-moving-to-trash t) in .emacs to be able to have files moved to ~/.Trash via d and then x in dired-mode. (This is in macOS.)

But if I want to delete a file (= move to the trash) that already exists in ~/.Trash, then I get error file-already-exists: File already exists: /Users/<myuser>/.Trash/<myfile>.

How can I specify in .emacs to (force-)overwrite files in ~/.Trash if they already exist in ~/.Trash?

Alternatively, how can I get Dired d-then-x to create a ~1, ~2 etc. version in Trash, every time a new file of the same base-name is moved there?

8
  • It all should work as you request. what exact version of emacs have you got? Also the only thing I have different is I don't set trash-directory and just leave it as nil
    – mmmmmm
    Jan 3 at 18:14
  • Hi, thanks for your help. I have GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-09-02. I also tried it without (setq trash-directory "~/.Trash"). I can then indeed delete a file, but I don't see it in ~/.Trash (so also not overwriting one that's already in ~/.Trash). I perhaps simply removes the file then or uses some other trash I'm not aware of. Jan 3 at 18:28
  • The function that should be called is move-file-to-trash SO try running atht and see if it does what you want
    – mmmmmm
    Jan 3 at 18:32
  • Ah, this failed (instead of the current file at point or selected, it tries to delete the whole folder the current file resides in, which fails due to missing permissions). But I saw from the error message that the 'trash' it that's used is ~/.local/share/Trash/files instead of ~/.Trash. So just the wrong folder so to say (but then changing that with trash-directory creates the original problem Jan 3 at 18:36
  • Then I think you have set something special - does this happen with emacs -Q
    – mmmmmm
    Jan 3 at 18:49

1 Answer 1

0

Thanks to user mmmmmm, I found the solution. I saw here that it's a macOS problem. Installing osx-trash (via brew install osx-trash or via MELPA) and then using

(when (eq system-type 'darwin)
  (osx-trash-setup))
(setq delete-by-moving-to-trash t)

in .emacs solved the problem (it now moves files to ~/.Trash and creates temporary names in ~/.Trash in case there is already a file with the same name).

Not the answer you're looking for? Browse other questions tagged or ask your own question.