Copy then rename and overwrite mass directory of files

March 23, 2012 at 11:27:42
Specs: Windows 7
Was hoping there is someone out there that can assist with a .bat file that will take a file name in directory 1 and will copy it to directory 2 by renaming it something else and overwriting what is already there.

I know that the xcopy /y feature does this for a point to point single file solution but i need to move a large group of files that look like #_CHAR_CHAR_.pdf and in the new directory make it look like #.pdf

example

H:\100_Title_of_job.pdf to I:\100.pdf
H:\1927_Title_of_job.pdf to I:\1927.pdf

any help you can give would be great as we are going to run this batch file automatically on sundays with windows scheduler.


See More: Copy then rename and overwrite mass directory of files

Report •


#1
March 23, 2012 at 14:39:21
I think this solves my answer but would love a verification

for /f %%Z in ('dir /b "DIR1"') do (
for /f "delims=_ tokens=1" %%X in ('echo %%Z') do (
for /f "delims=. tokens=2" %%Y in ('echo %%Z') do (
copy "DIR1\%%Z" "DIR2\%%X.%%Y"
)
)
)


Report •
Related Solutions


Ask Question