Copy and rename files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DXF
Posts: 3
Joined: 02 May 2013 09:51

Copy and rename files

#1 Post by DXF » 02 May 2013 10:14

After a some hours of "googling" I turn to you with a cry for help;

I´m trying to copy files from a folder structure as follow:

X:\posters\29-apr\SY\D1\001\X.pdf

The files shall be copied to an other location as follow:

Y:\29-apr\ and be named SYD1001.pdf

There are always only one file (pdf) in the folder. The name of the path differs for every file, but it is always \date\XX\YY\###\file.pdf and the destination shall always be \date\XXYY###.pdf (folder should be created if it´s not exists)

Grateful for the assistance

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Copy and rename files

#2 Post by Endoro » 02 May 2013 15:09

DXF wrote: (folder should be created if it´s not exists)

For this we need your date format. Post the output of:

Code: Select all

echo %date%

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy and rename files

#3 Post by foxidrive » 02 May 2013 18:59

This is untested.

It expects all the the dated folders to be directly under x:\posters and that all the PDF files under them are the ones to be copied.


Code: Select all

@echo off
pushd "x:\posters"
for /f "delims=" %%a in ('dir *.pdf /b /s /a-d') do (
for /f "tokens=3-6 delims=\" %%b in ("%%a") do (
md "y:\%%b" 2>nul
echo copying "%%a"
copy /b "%%a" "y:\%%b\%%c%%d%%e%%~xa" >nul
)
)
popd

DXF
Posts: 3
Joined: 02 May 2013 09:51

Re: Copy and rename files

#4 Post by DXF » 16 May 2013 10:45

Thank you very much. You have saved me a lot o work

8) :D

Post Reply