for file in *: will iterate over all files (and directories) in the current directory, saving each as $file.If you are satisfied they are correct, remove the echo and run again to actually rename. That will just print the commands that will be run. You can just run a little shell loop: for file in * do And, even with those, you would need something slightly different: perl-rename 's/-+_+_+//' *.*Īctually, since all you want is to remove everything after the last -, you could just use: perl-rename 's/(.*)-(.*)(\.*)/$1$2/' *.* Depending on your operating system, that might be available or installable as prename or perl-rename, but you want that one and not the rename from util-linux to use the regular expression syntax you were trying. The full source of RenameRegex is also available at GitHub if you want to fork or modify it.The syntax you tried to use is for the perl rename command. You can download RenameRegex (RR.exe) from here. ![]() ![]() Remove all numbers from the file names: RR.exe * "+" "" ![]() Renaming with a replacement of all "-" characters to "_": RR.exe * "-" "_" Simple rename without a regular expression: RR.exe *. NET regular expressions for the search and replacement strings, including substitutions (for example, "$1" is the 1st capture group in the search term). ![]() NET exposes an easy to use library for regular expressions, I created a small C# command-line app that can rename files via any regular expression. While there are a couple Windows GUI regular expression file renamers, I enjoy doing as much as I can from the command-line. Instead of hand-typing all of the new names, sometimes a nice regular expression would get the job done a lot faster. Every once in a while, I need to rename a bunch of files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |