Solved

Renaming Files during a copy Paste to New Folder

Posted on 2006-07-17
4
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

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…
A lot of things can happen during a presentation, worst of which is “death by PowerPoint.” Here are a few mistakes to avoid to make your slides clean.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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