Find and Replace String in filenames
Posted
by
shekhar
on Super User
See other posts from Super User
or by shekhar
Published on 2012-11-21T14:31:18Z
Indexed on
2012/11/21
17:03 UTC
Read the original article
Hit count: 275
I have thousands of files with no specific extensions. What I need to do is to search for a sting in filename and replace with other string and further search for second string and replace with any other string and so on. I.e.: I have multiple strings to replace with other multiple strings. It may be like:
- "abc" in filename replaced with "def" * String "abc" may be in many files
- "jkl" in filename replaced with "srt" * String "jkl" may be in many files
- "pqr" in filename replaced with "xyz" * String "pqr" may be in many files
I am currently using excel macro to get the file names in excel and then preserving original names in one column and replacing desired in the content copied in other column. then I create a batch file for the same. Like:
rename Path\OriginalName1 NewName1
rename Path\OriginalName2 NewName2
Problem with the above procedure is that it takes a lot of time as the files are many. And As I am using excel 2003 there is limitation on number of rows as well. I need a script in batch like:
replacestr abc with def
replacestr pqr with xyz
in a single directory. Will it be better to do in unix script?
© Super User or respective owner