Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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.

![]() |
![]() |
![]() |

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