Solved

Renaming Files during a copy Paste to New Folder

Posted on 2006-07-17
4
163 Views
Last Modified: 2010-04-13
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
0
Comment
Question by:quizzer
  • 2
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 140 total points
ID: 17126295
You need a batch file.  You can use the xcopy or copy commands together with the ability to amend strings in batch using %A:~0,10% for instance to get the first 10 characters of %A%.

Here we go

set source=H:\fdw
set dest=h:\fdw\changes

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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17126298
You might be better off having this moved to the MS-DOS TA (http://www.experts-exchange.com/Operating_Systems/MSDOS/) if you want any more complicated batch files...
Steve
0
 

Author Comment

by:quizzer
ID: 17129683
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
0
 

Author Comment

by:quizzer
ID: 17129711
I should end up with a file named

123456_AY.pdf

in the folder C:\TestingInfo_2
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question