?
Ask

How to batch-rename Windows (fat32) filenames? Rephrase this question

Question asked by Angela avatar

Answer

From Wikianswers

(Redirected from Windows (fat32) filenames)
Jump to: navigation, search

In windows (or linux actually, for that matter) is there any way to systematically change filenames? I have a large collection of music files and would like to (for example) switch them from all caps to lower case with the first letter capitalised, or strip off the album name from the beginning of the file (by stripping off the first, for example 10 characters of 10 files). Is there any way to do this that doesn't involve massive manual labour? Thanks! Intrigue 22:15, 10 Dec 2004 (UTC) (Question originally from Wikipedia. Used under GFDL)

[edit] Answers

Well, you could probably write a quick program that renames each file. If you already know some programming, it shouldn't be too hard, if not, well, then it's probably the same amount of work to do it all by hand. You might want to try looking around, though, there are plenty of people who write code to help manage MP3 collections, so you might want to try looking around on SourceForge or Freshmeat. --Cvaneg 22:35, 10 Dec 2004 (UTC)

The best, easiest, fastest and most comfortable way is to use a "batch rename" program (just google for it, there are hundreds of them). You can also do it manually (but less manually then renaming every file) by using a combination of MS Office and bat files. Basically you want to have a long text consisting of lines like:

ren "existing filename" "new filename"

This can be created using 3 columns in Excel. First column consists of "ren " strings. Second contains a list of old names that you can get using Select All + Copy in FAR Manager] or similar. The third column you can create using a combination of Excel text functions (but you need to know how to use them - basically you need to know how to use string search and how to copy substrings from certain position). Wikipedia:User:Paranoid

One of the best batch rename programs for Linux is called "KRename". If the renaming is simply meant to transform all filenames to all-lower-case, you can use the "tr" commandline utility. If you are sure that the current directory does not contain files with "weird" characters or blanks in their names, you can do it like this:

for file in *; do mv $file $(echo $file | tr [A-Z] [a-z]); done

Otherwise you have to use safeguards:

for file in *; do mv "\"${file}\" \"$(echo "${file}" | tr [A-Z] [a-z])\" ; done

But better first do test this command before you let it loose on your real files:

for file in *; do echo "\"${file}\" will be renamed to \"$(echo "${file}" | tr [A-Z] [a-z])\"" ; done

One other danger is this: originally, you may have 2 different files, with filenames only different in their capitalization, like "File123" and "fiLe123". Running this batch renaming will rename the first one successfully. When it comes to the second one, it will also rename it, but at the same time overwrite the first renamed one. Ooops, you just deleted a file you really wanted to keep.... And what would happen, if your 2 original files were "File123" and "file123"?

As you can see, batch renaming poses quite a few dangers. You may want to "collect" all the newly-generated filenames in a textfile and then screen the new names for any duplicates.

First collect all the original names:

for file in *; do echo "${file}" >> original-filenames.txt ; done

Then, collect all the new filenames:

for file in *; do echo "${file}" | tr '[A-Z]' '[a-z]' >> new-filenames.txt ; done

Last, use "sort" and "uniq" to find any duplicates which indicate where there are dangers in renaming:

cat original-filenames.txt new-filenames.txt | sort | uniq -c

All lines carrying a count number that is different from "1" indicate at least one original filename that is endangered. Pipitas 22:31, 18 February 2009 (UTC)

Answered by

Recent Unanswered Questions

  • Popular Categories