Batch file - writing a simple file copy

EICS

Member
Join Date
Dec 2008
Location
Melbourne, Australia
Posts
323
I need to write a simple Batch file Copy.BAT to copy a file.

lets call the original file c:\folder\FileA.xlsx and the New one c:\folder\FileA_Copy.xlsx

so what I need is

if file FileA_Copy.xlsx already exists in the directory c:\folder to delete it first and then make a copy of file FileA.xlsx as
FileA_Copy.xlsx

im very rusty on dos style commands anyone keen to write it for me i know its only a few lines of code but I cannot remember the syntax

thanks in advance.
 
Last edited:
I'm rusty too. But I think you can use the copy command and if the file already exist, it will overwrite it with the "y" switch.
This works on Windows 7

Copy C:\MyDir\FileA.xlsx C:\NewDir\FileA_Copy.xlsx /y
 
C:\WINDOWS\system32>copy /?
Copies one or more files to another location.

COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]

source Specifies the file or files to be copied.
/A Indicates an ASCII text file.
/B Indicates a binary file.
/D Allow the destination file to be created decrypted
destination Specifies the directory and/or filename for the new file(s).
/V Verifies that new files are written correctly.
/N Uses short filename, if available, when copying a file with a
non-8dot3 name.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.
/L If the source is a symbolic link, copy the link to the target
instead of the actual file the source link points to.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.

To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).
 

Similar Topics

Hello I was needing some help to writing a batch file that will add a value of "1" into a Windows "String Value" Registry key. The registry...
Replies
6
Views
2,166
Hello I have a folder that has txt files added as reports is ran. By default these reports is saved as a .txt file and no way to change this...
Replies
25
Views
11,692
Gday all, I'm currently working on a system that is using FTView ME running on a PV1500+ version 6.0. I have a datalog model created and all...
Replies
1
Views
3,467
First off, I am new to this forum so please bear with me. We currently are running several different brands of plcs and the one that gives the...
Replies
3
Views
2,642
I am trying to run a batch file from my VersaView Application to copy log files over to a USB Drive. I am unable to get the file to run...
Replies
0
Views
3,193
Back
Top Bottom