Solved

Renaming Files during a copy Paste to New Folder

Posted on 2006-07-17
4
161 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I should end up with a file named

123456_AY.pdf

in the folder C:\TestingInfo_2
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

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…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now