0

I want to have a function, which moves a file or optionally multiple marked files from one directory to a different directory in some parent folder. I managed to design a script which does the main things:

(defun multiple-rename (candidate)
(loop for cand in (helm-marked-candidates)
      do
      (spacemacs/rename-file cand)))
(defun move-from-downloads ()
  "helm interface to copy files from downloads"
  (interactive)
  (helm :sources `(
                   ((name . "My org files")
                    (candidates . ,(f-entries "~/Dropbox/Documents"))
                    (action . (("Rename" . multiple-rename))))
                   )))

The feature which is not present yet, which I would like to have is having some specified parent folder path for a target directory of renaming.

In other words, spacemacs/rename-file takes the file to rename as an argument and if it is not getting an a second argument which is here the case put up the prompt to select a filename where the files should be moved, the path in this prompt is however the path of the current buffer. Instead I would like to have the default path, which pops up in the prompt for renaming to be something different, e.g. home/mydefaultrenamepath. Would be happy to hear some solution, it doesn't need to use spacemacs/rename file, only the flow of having helm candidates to select and then standard directory to move files into (which should be able to be altered).

  • I would forego writing a function and instead use dired: set dired-dwim-target to t, open the first directory in one window, open the second directory in a second window, mark all the files you want to rename with m (or through a more automated procedure: dired provides various ways) and then press R. – NickD Mar 11 at 1:14
  • The process is faster how I intend it, if one of the used directories is always the same. Also I don't get it to work with spacemacs for some reason. Using dired-copy I always get the prompt of the target directory even if I have a second dired buffer open. – Rareform Mar 11 at 15:30
  • You need to set dired-dwim-target to t to avoid the prompt. Having a shortcut to open the first directory only adds one more keystroke - for me, the flexibility of this solution overshadows any advantage a custom-made solution has. – NickD Mar 11 at 17:01
0

M-x find-lisp-find-dired to find files in a directory matching user given regular expression. Please note this command supports unicode on Windows out of box.

Select all files and M-x dired-do-rename.

Surely you can use above command in your own code.

| improve this answer | |
0

Here's a command that shows files from your-initial-directory, and moves/renames the marked/selected files to your-target-directory. Tested with ./emacs-helm.sh.

(defvar your-initial-directory "~/Downloads/")
(defvar your-target-directory "~/Documents/")

(defun multiple-rename (_)
  (let ((files (helm-marked-candidates)))
    (helm-dired-action your-target-directory
                       :files files
                       :action 'rename)))

(defclass helm-user-rename (helm-source-ffiles)
  ((action :initform '(("Rename files" . multiple-rename)))))

(defun helm-rename ()
  (interactive)
  (require 'tramp)
  (helm :sources (helm-make-source "Rename files" 'helm-user-rename)
        :input your-initial-directory))
  1. M-x helm-rename
  2. C-SPC to mark the files you want to rename
  3. RET
| improve this answer | |
  • The script doesn't seem to work, after selecting the first file it just opens a file. I would also like to select the file from the helm sources window (it is fancier). – Rareform Mar 10 at 14:06
  • You had to press f2 or TAB to select the correct action. In any case, I rewrote the answer. – jagrg Mar 11 at 0:51

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.