how do i copy a file without overwiting?

Join Discord

dreamcatcherei

Dedicated Member
Dedicated Member
Jan 2, 2004
126
0
62
im making bat file to use as a taskmanger to bkup a couple files every 2 hours but in the bat i need string to stop it overwritting the existing file its already bked up any ideas?
 

zuess

Dedicated Member
Dedicated Member
Mar 23, 2004
104
0
62
that long since i used dos im presuming your using dos command in a bat file?


if you are get it to change the attributes to read only once it copies the files something like attrib *.* -r i will try one later to see if i can comeup with a script for you so it wont write over a read only file (dont hold me to this tho as i say its a long time since i used dos or had to use dos

[edit] or you could place a copy command to confirm with you if you want to overwrite a file or not
 
Last edited:
Upvote 0

zuess

Dedicated Member
Dedicated Member
Mar 23, 2004
104
0
62
ok try this
copy :\test1*.* c:\test2\
attrib c:\test2\*.* +R

this will allow you to copy from one directory to another then after the files are finished copying it will set the attribute of the file to read only so if a filename of the same name is trying to be copied you get the error access is denied (you wont see this as the bat file processes to quickly on a small amount of files but you will see if if the files to be copied are alot in number)

to change the attribute back you can use this

attrib c:\test2\*.* -R

other attibutes are:
  • hidden= -H to remove the hidden attributes +H to add the hidden attributes
  • system= -S to remove the system attributes +S to add the system attributes
  • archive= -A to remove the archive attributes +A to add the archive attributes
there is also another way of doing it just by letting you choose if the file should be copied

copy /-y c:\test1\*.* c:\test2\

hope this can be of use to you

and thanks for reminding me that i was arround when people were still using dos coding

if this is what you need i hope it works for you if not do as it was posted before and use a VB script
 
Upvote 0

Kaori

LOMCN MiR3 Queen!
VIP
Jun 3, 2004
3,584
38
285
Canada
ahh zuess you bring another idea... easier than vbscript...

your batch file can look like this...

Code:
@echo off
"C: or Your drive letter"
CD "your backup dir"
COPY /Y backup8.rar backup9.rar
COPY /Y backup7.rar backup8.rar
COPY /Y backup6.rar backup7.rar
COPY /Y backup5.rar backup6.rar
COPY /Y backup4.rar backup5.rar
COPY /Y backup3.rar backup4.rar
COPY /Y backup2.rar backup3.rar
COPY /Y backup1.rar backup2.rar
DEL /Q backup1.rar
"C:\Program Files\WinRAR\RAR.exe" a -r backup1.rar "C:\directory to backup\*"
 
Upvote 0