I will have a set of filenames (in some pre-determined directory like C:\files) formatted like the following: 1213C-1.jpg
1213C-2.jpg
1214C-1.jpg
1215C-1.jpg
1215C-2.jpg
1215C-3.jpgand want to rename these files by putting the sequence numbers at the end of the extension like so:
1213C.jpg_1
1213C.jpg_2
1214C.jpg_1
1215C.jpg_1
1215C.jpg_2
1215C.jpg_3
then i think this might work (switching to multi-line mode): @echo off & setlocal
set destdir=c:\directoryB
cd /d C:\Users\user1\Desktop\Test
for /f "tokens=1-3 delims=-." %%a in ('dir /b') do move %%a-%%b.%%c %destdir%\%%a.%%c_%%b
pause
:: endas for script #2, you might have left the dot in the delims, which would account for its failure. delims should just be: "delims=-"
@for /f "tokens=1-3 delims=-." %%a in ('dir /b') do ren %%a-%%b.%%c %%a.%%c_%%b
:: endor, if you know they're all .jpg extensions:
@for /f "tokens=1-2 delims=-" %%a in ('dir /b *.jpg') do ren %%a-%%b.jpg %%a.jpg_%%b
:: endnot tested! Test using "echo" before first launch! (ie: insert "echo" in front of "ren")
Thanks but doesn't appear to be working. Just get a quick command prompt that goes away quickly and nothing happens.
Forgot to add that after renaming, I need to move them to another directory. So, files would be in C:\DirectoryA, rename the files and move to C:\DirectoryB
append one line to end of batch:
pausethat should allow you to see what happened, i hope.
Now, moving the goalposts issue: do you want to rename the files in the current directory AND copy (with new name) to dest.dir? or do you want to MOVE the files to the new name in the dest.dir. (or, another possiblity: COPY the file from current directory to dest-dir\NEWNAME leaving the old original names/files in the source directory.) Knowing you want the files renamed and copied/moved still leaves these 3 options in source dir: delete (move), rename (rename & copy) , or leave as is (copy to dest\newname). Hope this is clear.
ps: my current interpretations is option 2: rename in cd and copy to dest\newname, but I'll wait for confirmation.
OK...getting close on this. I ran it and saw that it was appending an extra .jpg to the end of the file names. Here's the output from the command prompt: ren 11445-1.jpg.jpg 11445.jpg_1.jpg
They system cannot find the file specified...With regard to your question above, I would like to move these files after they are renamed to another directory. Do not want to keep files in the original directory. Would prefer to move or cut/paste to the new dir.
I tried your first script and it actually seems to work. These will always be .jpg files so I started out with script #2 which gave me the error I mentioned above. I made a minor change to set the working directory and ran the script and the files are renamed correctly. Here's the script as I have it now: cd /d C:\Users\user1\Desktop\Test
@for /f "tokens=1-3 delims=-." %%a in ('dir /b') do ren %%a-%%b.%%c %%a.%%c_%%b
:: end
pauseJust need to figure out how to cut/paste to new dir and I think we'll be good to go!
then i think this might work (switching to multi-line mode): @echo off & setlocal
set destdir=c:\directoryB
cd /d C:\Users\user1\Desktop\Test
for /f "tokens=1-3 delims=-." %%a in ('dir /b') do move %%a-%%b.%%c %destdir%\%%a.%%c_%%b
pause
:: endas for script #2, you might have left the dot in the delims, which would account for its failure. delims should just be: "delims=-"
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |