For every question, there's an answer -- and you'll find it here!


Printer-friendly copy
Top The PC Q&A Forum The Computer Forum topic #566863
View in linear mode

Subject: "Batch file to copy and rename files" Previous topic | Next topic
harryThu Feb-25-21 04:43 AM
Charter member
179 posts
Click to send email to this author Click to send private message to this authorClick to view this author's profileClick to add this author to your buddy list
"Batch file to copy and rename files"


          

I regularly need to copy and rename files whose filenames have various lengths but always end in the same three characters, which I need to change to another three characters.

For example, if the source files have the names "ABC123BananaAB1.txt" and "DEF345PineappleAB1.docx", then I need to copy them to target files with the names "ABC123BananaXYZ.txt" and "DEF345PineappleXYZ.docx" respectively. In other words, I need the target filenames to be the same as the source filenames but with the last three characters changed from "AB1" to "XYZ".

I tried using a bat file containing the command "copy *AB1.* *XYZ.*", but it didn't work properly. How can I get this to work?

  

Alert Printer-friendly copy | Reply | Reply with quote | Top

Replies to this topic
Subject Author Message Date ID
RE: Batch file to copy and rename files
Feb 25th 2021
1
RE: Batch file to copy and rename files
Feb 25th 2021
3
RE: Batch file to copy and rename files
Feb 25th 2021
2
RE: Batch file to copy and rename files
Mar 01st 2021
4
      RE: Batch file to copy and rename files
Mar 12th 2021
5
           RE: Batch file to copy and rename files
Mar 15th 2021
6

Paul DThu Feb-25-21 03:15 PM
Charter member
10201 posts
Click to send email to this author Click to send private message to this authorClick to view this author's profileClick to add this author to your buddy list
#1. "RE: Batch file to copy and rename files"
In response to harry (Reply # 0)
Thu Feb-25-21 03:19 PM by Paul D

  

          

Bulk Rename Utility will do that for you, and much more besides. I've used it for years, and it's absolutely free. I'm assuming the files to be changed are in the same folder, as the software's major limitation is that it can only work in one folder at a time.

https://www.bulkrenameutility.co.uk




Paul D

  

Alert Printer-friendly copy | Reply | Reply with quote | Top

    
PcqandamanThu Feb-25-21 06:25 PM
Member since Nov 18th 2002
2143 posts
Click to send email to this author Click to send private message to this authorClick to view this author's profileClick to add this author to your buddy list
#3. "RE: Batch file to copy and rename files"
In response to Paul D (Reply # 1)


          

QUOTE:
Bulk Rename Utility will do that for you, and much more besides. I've used it for years, and it's absolutely free. I'm assuming the files to be changed are in the same folder, as the software's major limitation is that it can only work in one folder at a time.

https://www.bulkrenameutility.co.uk




Paul D

Thanks for this.
I always like it when there is a portable version.
BTW in the current version you can specify sub-directories so with a bit of moving folders around you could scan more than one folder's files.

  

Alert Printer-friendly copy | Reply | Reply with quote | Top

therubeThu Feb-25-21 03:50 PM
Member since Jan 22nd 2003
16574 posts
Click to send private message to this authorClick to view this author's profileClick to add this author to your buddy list
#2. "RE: Batch file to copy and rename files"
In response to harry (Reply # 0)
Thu Feb-25-21 04:00 PM by therube

  

          

And, if you're looking for a command-line program, Bulk Rename Utility has a program, Bulk Rename Command, https://www.bulkrenameutility.co.uk/Download.php, that I would think could do it.


Quote:

C:\TMP\BRU>brc.exe /replaceci:ab1:XYZ


Processing Folder C:\TMP\BRU\

Filename Concerto in D Minor (RV 454) for Oboe, Strings, and Harpsichord - I. Allegro requires no changes

Filename ABC123BananaAB1.txt would be renamed to ABC123BananaXYZ.txt

--------------------------------------
BANK OF AMERICA.COM ONLINE BANKING SUCKS IN THE HUGEST WAY IMAGINABLE

Newegg.com's new image gallery layout sucks in the hugest way imaginable too !
And now they're using JavaScript to "turn" pages to boot ! SUCKS

  

Alert Printer-friendly copy | Reply | Reply with quote | Top

    
harryMon Mar-01-21 02:31 AM
Charter member
179 posts
Click to send email to this author Click to send private message to this authorClick to view this author's profileClick to add this author to your buddy list
#4. "RE: Batch file to copy and rename files"
In response to therube (Reply # 2)


          

Thanks for your replies. It appears that the Batch Rename Command utility will do part of what I need, but it appears that I still need an additional command to make a copy, because I want to end up with the original file AND a renamed copy.

Example:

1. Start with one file ("ABC123BananaAB1.txt").
2. Run batch file to copy/rename.
3. End up with two files ("ABC123BananaAB1.txt" AND "ABC123BananaXYZ.txt").

  

Alert Printer-friendly copy | Reply | Reply with quote | Top

        
Paul DFri Mar-12-21 03:59 PM
Charter member
10201 posts
Click to send email to this author Click to send private message to this authorClick to view this author's profileClick to add this author to your buddy list
#5. "RE: Batch file to copy and rename files"
In response to harry (Reply # 4)
Fri Mar-12-21 04:00 PM by Paul D

  

          

Open relevant folder
Select files to copy/rename.
Ctrl~C
Ctrl~V (in the same folder)
You will then have your original and copy files, named FilenameABC.aaa and FilenameABC- Copy.aaa respectively.
Using BRU, rename all the "- Copy" files as required.




Paul D

  

Alert Printer-friendly copy | Reply | Reply with quote | Top

            
harryMon Mar-15-21 10:59 PM
Charter member
179 posts
Click to send email to this author Click to send private message to this authorClick to view this author's profileClick to add this author to your buddy list
#6. "RE: Batch file to copy and rename files"
In response to Paul D (Reply # 5)
Mon Mar-15-21 11:01 PM by harry

          

Thanks for your reply. A batch file containing the following command does the renaming OK, after using Ctrl+C & Ctrl+V to copy and paste the source file manually.

brc64.exe /execute /replaceci:"AB1 - Copy":XYZ

Is it possible to include a command in the batch file to do automatically what Ctrl+C & Ctrl+V does manually; i.e., to copy *AB1.* to *AB1 - Copy.*?

  

Alert Printer-friendly copy | Reply | Reply with quote | Top

Top The PC Q&A Forum The Computer Forum topic #566863 Previous topic | Next topic
Powered by DCForum+ Version 1.27
Copyright 1997-2003 DCScripts.com
Home
Links
About PCQandA
Link To Us
Support PCQandA
Privacy Policy
In Memoriam
Acceptable Use Policy

Have a question or problem regarding this forum? Check here for the answer.