5

I am trying to create a simple function for dired where I would be able to call the function on current (or marked) files and then quick move the current (or marked) files to a pre-defined directory.

I know I need to write a function and use dired-do-rename but I am unclear of other steps (I have zero coding skills :))

This is what I have so far:

(defun z/dired-move-2home ()
  (interactive)
  (dired-do-rename FILE/MARKED FILES "~/Downloads"))
  • I don't understand what you want to do. It sounds like you just want to do dired-do-rename. What's different about what you want? – Drew May 11 '16 at 14:55
  • thx drew, yeah i should be clearer. i mean do the copy to a pre defined directory ,as is copy item X/marked item X to dir Y (ie "~/Downloads"). so when i issue z/dired-move-2home it will copy X to ~/Downloads. is that clearer? Z – zeltak May 11 '16 at 16:20
4

Below solution temporarily overrides the dired-dwim-target-directory to simply return whatever value you set to the temporary variable default-dest-dir. In this example, that value is set to "/my/default/to/dir". You will need to set that to your default destination directory.

(defun my/dired-do-rename (&optional arg)
  (interactive "P")
  (cl-letf* ((default-dest-dir "/my/default/to/dir")
             ((symbol-function 'dired-dwim-target-directory)
              (lambda ()
                default-dest-dir)))
    (call-interactively #'dired-do-rename)))
(define-key dired-mode-map (kbd ";") #'my/dired-do-rename)

How to use this

  1. Mark the files in dired that you need to move to default-dest-dir, using the m key.
  2. Hit ;, which is bound to my/dired-do-rename above.
  3. You will see the minibuffer field pre-filled with the default-dest-dir value.
  4. Hit RET to continue (or tweak the pre-filled directory if needed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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