E=mc2
asked on
Looping successfully through find and rename routine
If this script finds several instances of "12345678" or "910111213", I would like for it to append a 1,2,3,4...etc to the file name which is being written.
For instance if it finds several instances of "12345678" in various files, then I need for it to write to FILE.txt, FILE1.txt, FILE2.txt and so forth:
setlocal enabledelayedexpansion
for %%a in ("C:\Users\Desktop\New folder\*.ed") do (
find "12345678" "%%~fa" && ren "%%~fa" FILE.txt
find "910111213" "%%~fa" && ren "%%~fa" OTHER.txt
)
For instance if it finds several instances of "12345678" in various files, then I need for it to write to FILE.txt, FILE1.txt, FILE2.txt and so forth:
setlocal enabledelayedexpansion
for %%a in ("C:\Users\Desktop\New folder\*.ed") do (
find "12345678" "%%~fa" && ren "%%~fa" FILE.txt
find "910111213" "%%~fa" && ren "%%~fa" OTHER.txt
)
ASKER
Thanks Bill. Seems to work, however why do you have to Set FileCounts?
set FileCount=0
Set FileCount=0
What if I added another 5 searches for a total of 7, would I need 7 'set FileCounts'?
set FileCount=0
Set FileCount=0
What if I added another 5 searches for a total of 7, would I need 7 'set FileCounts'?
ASKER
Bill. Lastly, if I want to write the new FILE.txt files in C:\File\ and in new OTHER.txt files in C:\Other, to ask this question would I have to start a new thread or could you also answer it here?
Thanks for your help.
Thanks for your help.
Sorry,
These:
set FileCount=0
Set FileCount=0
should have been:
set FileCount=0
Set OtherCount=0
and no, you wouldn't need any more than that. These just start the sequence off for the two types of files we write, and then we increment for each file we output.
So, if you want to move the files to a different folder, do you want to copy, or move?
~bp
These:
set FileCount=0
Set FileCount=0
should have been:
set FileCount=0
Set OtherCount=0
and no, you wouldn't need any more than that. These just start the sequence off for the two types of files we write, and then we increment for each file we output.
So, if you want to move the files to a different folder, do you want to copy, or move?
~bp
ASKER
Thanks Bill. Move would be fine actually.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Bill, seems to work.
Welcome, glad that helped.
~bp
~bp
Open in new window
~bp