Renaming Files during a copy Paste to New Folder

Posted on 2006-07-17
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
Question by:quizzer
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
LVL 43

Accepted Solution

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


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

LVL 43

Expert Comment

by:Steve Knight
ID: 17126298
You might be better off having this moved to the MS-DOS TA ( if you want any more complicated batch files...

Author Comment

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


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

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


Author Comment

ID: 17129711
I should end up with a file named


in the folder C:\TestingInfo_2

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loss of RDP via 4 246
Migrate DFS role 3 861
DNS server query - zone verus cache 5 195
Screen Mirroring 7 89
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…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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