We'd like to remind Forumites to please avoid political debate on the Forum... Read More »
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
Utility to add prefix to all filenames in a folder
Options

howsoonisnow
Posts: 64 Forumite
in Techie Stuff
There are dozens of utilities available which will perform various batch file operations, so I am hoping that someone can recommend one. It might help if I explain what I am trying to do. I want to add the prefix [CD] to all filenames in certain folders within My Music. This is to enable me to exclude these from my regular backup - I don't need to back up mp3 files which are themselves backups of actual CDs. I am running XP pro. Hope this is clear - tell me if not.
0
Comments
-
'mon the Totalcommander!They say it's genetic, they say he can't help it, they say you can catch it - but sometimes you're born with it0
-
get a dosprompt, goto the folder, REN *.* *.cd
doneUtinam logica falsa tuam philosophiam totam suffodiant.0 -
You missed the word prefix in the OP.
It would also have been good to know that you had tested it before posting.0 -
oops
.......ren *.* cd*.*Utinam logica falsa tuam philosophiam totam suffodiant.0 -
Did you test it? I did. It doesn't work...
I then tried
for %a in (*.*) do ren "%a" "CD%a"
and this did work. No idea why your version didn't!0 -
for %a in (*.*) do ren "%a" "CD%a"
Thanks, I tried this command and it worked. Is there an additional instruction I can add to the command which will perform the rename for every file in every sub folder if I start at "my documents\my music\CD backups"? There are hundreds of sub folders and it will take ages to type a change directory command for every sub folder before running the command .
Alternatively, is there any way of opening a command prompt window which is set to the folder currently being viewed in windows explorer?0 -
add to the end /s
%a in (*.*) do ren "%a" "CD%a" /s
might do it0 -
Unfortunately the REN command doesn't have a /S switch. You will need something rather more complicated.
I really suggest you make a complete copy of your CD Backups directory and all subdirectories "somewhere safe" before you start, because it will be very messy to recover if anything goes wrong! Windows Explorer is what I'd use, myself.
You seem quite confident with command prompts and NOTEPAD (I hope!) so cut and paste the following lines into a file called (say) PREFIXCD.BAT
:: rename all files in a directory/subdirectory path to have CD at the front
setlocal
cd "%userprofile%\my documents\my music\CD backups"
PAUSE
set log=%~n0.log
if exist %log% del %log%
for /r %%a in (*.*) do ECHO ren "%%~fa" "CD%%~nxa" >> %log%
notepad %log%
endlocal
This BATch file can go anywhere you like (within reason!), and the log file is put in your "CD Backups" directory.
Run PREFIXCD.BAT once, and check that the CD command gives you the correct results (see the PAUSE command on-screen) then review the log file which results, as displayed in NOTEPAD*. If you are happy with what comes out, edit the BATch file and remove the ECHO word just in front of the ren. This will cause it to actually do the job when you run PREFIXCD.BAT again.
Good luck!
* I just copied a few random directories and files into a CD Backups directory on my machine, and one of the resulting renames was
ren "C:\Documents and Settings\John\My Documents\My Music\CD Backups\SysInternals\Copy of website as at 22JUL2006\AccessChk.html" "CDAccessChk.html"
(this single line may wrap badly!).
LATER
Please note that this will rename every single file in CD Backups and below to have the CD prefix. Please give more details if this is NOT what you want...0 -
Thanks John for the reply posted above - I will try this! I had got to the stage where I thought I was going to place a copy of cmd.exe in every folder, so as to get the command line to show that directory. I would then have pasted in for %a in (*.*) do ren "%a" "CD%a" and run it, before closing the command prompt window and repeating the process in the next fiolder, and the next, and the next...0
This discussion has been closed.
Confirm your email address to Create Threads and Reply

Categories
- All Categories
- 351.2K Banking & Borrowing
- 253.2K Reduce Debt & Boost Income
- 453.7K Spending & Discounts
- 244.2K Work, Benefits & Business
- 599.3K Mortgages, Homes & Bills
- 177K Life & Family
- 257.6K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.2K Discuss & Feedback
- 37.6K Read-Only Boards