Computing.Net > Forums > Programming > batch file copy without overwrite

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch file copy without overwrite

Reply to Message Icon

Name: barberboy
Date: June 17, 2005 at 09:12:28 Pacific
OS: win98see
CPU/Ram: p4/128
Comment:

I would like to write a batch file that would copy files from one directory to another but not overwrite OR abbort if a file already exists with that name. If a file already exists, i would like it to rename the newer copied file and continue copying the file.

For instance, if i wanted to copy the file 'Dir1\999999999\Copy 1.max' to Dir2, it would create the folder 999999999 if it did not exist and copy 'Copy 1.max' into it. If there was already a '999999999\Copy 1.max' in Dir2, it would rename the file to 'Copy 1_2.max' in the Dir2\999999999\ folder.

The new file name is NOT important at all, just as long as the file being copied is renamed if a file with that name already exists in Dir2 instead of overwriting or abborting. Also, that this will be for moving dozens of folders and hundreds of files from Dir1 to Dir2 just by running the batch file.

Another possible option would be to rename the files as [date]_[time].max before they were copied to the new directory. That would ensure that filenames would be unique. I can rename the files as [date]_[time].max by running a batch file on a specific folder, like
[Batchfile.bat] [Foldername]
but i don't know how to do it for several folders at once.

Either option (either the Copy 1_2.max or the [date]_[time].max) will work fine, just as long as all the files are copied and no existing files are overwritten.

Another note: there are other files in the folders that are not *.max files that should not be renamed. These are hidden and possibly system files though, so they could be easily avoided.

Thank you in advance for your help. I have been referencing this forum alot lately, but can't quite accomplish this task. Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: June 17, 2005 at 09:40:58 Pacific
Reply:

I would do something like:

::** one.bat
for %%M in (*.max) do call two %%M
::**

::** two.bat
if exist \dirname\%1 copy %1 \dirname\%date%%time%.max

:: that's ONE line

if not exist \dirname\%1 copy %1 \dirname\
::**

M2


If at first you don't succeed, you're about average.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch file copy without overwrite

Batch file copy and Rename www.computing.net/answers/programming/batch-file-copy-and-rename/18689.html

batch file to copy to many folders www.computing.net/answers/programming/batch-file-to-copy-to-many-folders/17504.html

batch file to find and copy www.computing.net/answers/programming/batch-file-to-find-and-copy/9236.html