Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a batch file to copy and rename file

Tags:

I need to write a batch file that copies a file to a new folder and renames it.

At the moment, my batch file consists of only this command:

COPY ABC.PDF \\Documents 

As you can see, it only copies the file ABC.pdf to the network folder Documents.

However I need to change this so it renames the file ABCxxx.pdf, where xxx is a text variable that I would like to set somewhere in the batch file.

For example, if xxx = _Draft, then file would be renamed ABC_Draft.pdf after it is copied.

like image 462
Estate Master Avatar asked Jun 17 '10 00:06

Estate Master


People also ask

Is there a way to batch rename files?

To batch rename files, just select all the files you want to rename, press F2 (alternatively, right-click and select rename), then enter the name you want on the first file. Press Enter to change the names for all other selected files.


1 Answers

Make a bat file with the following in it:

copy /y C:\temp\log1k.txt C:\temp\log1k_copied.txt 

However, I think there are issues if there are spaces in your directory names. Notice this was copied to the same directory, but that doesn't matter. If you want to see how it runs, make another bat file that calls the first and outputs to a log:

C:\temp\test.bat > C:\temp\test.log 

(assuming the first bat file was called test.bat and was located in that directory)

like image 85
thursdaysgeek Avatar answered Oct 01 '22 02:10

thursdaysgeek