Here’s something I can’t figure out: When using dired to manage files, let’s say I have a top level directory with a ton of subdirectories, each with a GoPro video inside (unique name/time/date for each file name). How do I move them all at once to that top level directory for easier management/renaming? I don’t want to have to go into each directory and move them one at a time with R. Let’s say all of the files are MP4 or HEVC.
For an elisp solution (not dired
, still in Emacs):
(rename-file filename ))
(directory-files-recursively "."))
You can filter via the second argument of directory-files-recursively
which files you want to list (using a regexp), or use any test you want in the lambda.
Not the fastest if you have a large amount of files, as it is pure elisp.
I dunno, sounds like a one liner in cli … unless you need to do this many times in the future or just want to force it into Emacs for fun (which is okay :), strikes me as a 10s thing to do on cli if you’rr a Mac or Unix-like user
cd /to/top mv */*mov .
Repeat for other file type.
That assumes they’re only one level deep
Another one liner …
find /top -name “*mov” -exec “mv {} /top” ;
Be careful as just tapping out on phone but you get the idea
You don’t need to move files around just to bulk rename them. If you want to do it, sure, you can, but you don’t have to.
In your top level directory:
- C-u C-x d (alternatively C-u M-x dired)
You will be in minibuffer now. Be sure dired listing switches have -l and -R option; -l is probably already there among anything else you might use; just type space and add -R at the end and type Return (Enter)
Now you will have a Dired buffer with al the subdirectories and files in them listed in the same buffer.
- C-x C-q in Dired to switch to WDired mode (I have bound it in my Emacs to C-S-r for easier typing)
You are now in “writeable dired” mode where you can edit all file names as if it were an ordinary text buffer. You can also use replace-string for example to replace a part of the name in all filenames at once, regex-replace, etc. You can do it manually, or whatever else you would do in a text buffer.
- C-c C-c to save your changes when you are done; all files will be updated.
I know this is the emacs subreddit but I think it would be a better task for just the CLI ‘find’ command with mindepth and exec
You could use M-x find-name-dired
to list the files matching a pattern in the directory and subdirectories in a Dired buffer. See: https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired-and-Find.html
The manual also says that you could use the recursive flag for ls
, but I’ve never tried it. See: https://www.gnu.org/software/emacs/manual/html_node/emacs/Subdirectories-in-Dired.html