|
Answer» Several people here at my office scan FILES onto their C drive during the day. At night time we run a batch file which will copy those files to a central file server.
My problem comes when a file name already exist on the server, thus leaving the would-be copied file sitting on the C drive. This then requires me to MANUALLY add a 1 to the end of the file name then copy.
Here is what my existing batch file looks like:
Code: [Select] rem @echo off dir \\scanner1\scan >> c:\scanm\scanm1.log
move /-y \\scanner1\scan\pic*.* e:\data\arch\scan\pic >> c:\scanm\scanm1.log move /-y \\scanner1\scan\doc*.* e:\data\arch\scan\doc >> c:\scanm\scanm1.log
dir \\scanner1\scan >> c:\scanm\scanm1e.log
I would like to add something into this batch file so say if say I try to copy a picturesky.jpg to the server and there already exists a picturesky.jpg, it will rename the new file to picturesky1.jpg or something of that nature.
Any thoughts or HELPS would be appreciated.You mentioned a server environment, so this may work:
Code: [Select] set from=\\scanner1\scan set to=e:\data\arch\scan\pic
for /f "tokens=1-2 delims=." %%a in ('dir /b %from%\pic*.*') do ( if not exist %to%\%%a.%%b (move /-y %from%\%%a.%%b %to% >> c:\scanm\scanm1.log) else (call :FindPic) ) GOTO :eof
:FindPic call set /a tail=%%tail%%+1 if not exist %to%\%%a%tail%.%%b (move /-y %from%\%%a.%%b %to%\%%a%tail%.%%b >> c:\scanm\scanm1.log & set tail=0) else (call :FindPic)
FindPic is recursive to find the next available file name. A better solution would be Windows Script
Hope this helps.
PS. The code SNIPPET for pic* files. You can take care of the doc* files.
|