Link to home
Start Free TrialLog in
Avatar of quizzer
quizzer

asked on

Renaming Files during a copy Paste to New Folder

We have PDF Files located in a shared folder we have H:\FDW
All of the files have a similar naming convention like this
AY-Claims Detail Report - Agent 123456.pdf

I need a simple procedure to copy these files to a folder named H:\FDW\Changes

and rename them so they appear like this

123456_AY.PDF in the folder H:\FDW\Changes

Basically take the 6 characters to the left of the period
plus an underscore
plus the left 2 characters
plus .PDF

How can i do this and where can i execut this from?  Thanks
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might be better off having this moved to the MS-DOS TA (https://www.experts-exchange.com/Operating_Systems/MSDOS/) if you want any more complicated batch files...
Steve
Avatar of quizzer
quizzer

ASKER

dragon thanks for the advice.  For testing purposes I am trying to do this on my C drive for now

2 folders

source C:\TestingInfo_1 (Folder contains file named AY-Claims Detail Report - Agent 123456.pdf)
Dest C:\TestingInfo_2 (Nothing is in TestingInfo_2)

I have a .bat File named Rename.bat

Code is here
*************************
set source=C:\TestingInfo_1
set dest=C:\TestingInfo_2

for /F "tokens=*" %%A in ('dir /b %source% 2^>nul') do call :process %%A

goto end

:process

set oldname=%1
set name2=%oldname:~-10%
set newname=%name2:~0,6%_%oldname:~0,2%.PDF
echo Changing %oldname% to %newname%
xcopy %source%\%oldname% %dest%\%newname% /Y

:end
***************************
When I run the bat file it is trying to do something but nothing happens.  Any ideas???

Thanks
Avatar of quizzer

ASKER

I should end up with a file named

123456_AY.pdf

in the folder C:\TestingInfo_2