I have a folder that contains thousands of .pdfs each file named by a 5 or 6 digit account number. I have a script that will create a folder of the same account number and move the file into it.
echo ON
Title Move files Routine
setlocal enabledelayedexpansion
pushd D:\test1\source\
for /f "tokens=*" %%1 in ('dir /a-d /b D:\test1\source\*.pdf') do (
set filename=%%1&set dirname=!filename:~0,6!
if not exist D:\test1\source\!dirname! (md D:\test1\source\!dirname!)
move %%1 D:\test1\source\!dirname!\
)
PAUSE
However, I need to run this script daily as new filed are added to the source directory and if the script moves a file to a directory that already has a file of the same name, it will overwrite it instead of renaming it. How can I tweak my script to address this problem. My options appear to be
- append to existing file (this seems to require additional software)
- Rename (e.g. 123456.pdf to 123456_001.pdf)
- Add date to filename (e.g. 123456.pdf to 123456_MMMMddyyyy.pdf)
I am fine with any of these options, I just don't know how to put that in the script. Any help is much appreciated.
No comments:
Post a Comment