vlsllp
asked on
Batch file that will move PDFs to corresponding folders
Hello,
Our financial institution is using a system that generates client PDFs in a specific format. For example, the system we use exports PDFs in location \\serverA\clientPDFs\ as this format:
1455-Douglas T Thompson-2013Archivek1Pack age.pdf
4785-Cheri Lockson-2013Archivek1Packa ge.pdf
7899-Thomas Pete-2012Archivek1Package. pdf
etc... (we have hundreds of them waiting to be moved)
but all clients of different types are in 1 folder instead of its own assigned client folder.
I need a batch file that will migrate the clients above to its corresponding client ID. An example of its final result would be:
\\serverB\client\1455\1455 -Douglas T Thompson-2013Archivek1Pack age.pdf\
\\serverB\client\4785\4785 -Cheri Lockson-2013Archivek1Packa ge.pdf\
\\serverB\client\7899\7899 -Thomas Pete-2012Archivek1Package. pdf\
anything will help, thanks in advance!
Our financial institution is using a system that generates client PDFs in a specific format. For example, the system we use exports PDFs in location \\serverA\clientPDFs\ as this format:
1455-Douglas T Thompson-2013Archivek1Pack
4785-Cheri Lockson-2013Archivek1Packa
7899-Thomas Pete-2012Archivek1Package.
etc... (we have hundreds of them waiting to be moved)
but all clients of different types are in 1 folder instead of its own assigned client folder.
I need a batch file that will migrate the clients above to its corresponding client ID. An example of its final result would be:
\\serverB\client\1455\1455
\\serverB\client\4785\4785
\\serverB\client\7899\7899
anything will help, thanks in advance!
Try this:
@echo off
for %%a in (*.pdf) do (call :DoIT %%a)
goto :EOF
:DoIt
echo.
set IDA=%1
set ID=%IDA:~0,4%
md %ID%
move "%1" %ID%
)
ASKER
We appreciate the quick reply!
i tried inputting your code into a .bat file,
Prior testing this on my server I created 2 folders on my desktop: "%USERPROFILES\Desktop\ser verA\" and "%USERPROFILES\Desktop\ser verB\
here's what I have so far, but didn't seem to work. thanks again
@echo off
for /f %%a in ('dir /b %USERPROFILE%\Desktop\serv erA\*.PDF' ) do (
call:MoveThisFile %%a
)
goto:EOF
:MoveThisFile
set file=%1
set node=%file:~0,4%
rem Comment out the following two lines when you're ready to run this for real
echo if not exist %USERPROFILE%\Desktop\serv erB\%node% mkdir %USERPROFILE%\Desktop\serv erB\%node%
echo move %USERPROFILE%\Desktop\serv erA\%file% %USERPROFILE%\Desktop\serv erB\%node% \.
rem Remove the "rem" comments from these next two lines when you're ready to run this for real
if not exist %USERPROFILE%\Desktop\serv erB\%node% mkdir %USERPROFILE%\Desktop\serv erB\%node%
move %USERPROFILE%\Desktop\serv erA\%file% %USERPROFILE%\Desktop\serv erB\%node% \.
goto:EOF
i tried inputting your code into a .bat file,
Prior testing this on my server I created 2 folders on my desktop: "%USERPROFILES\Desktop\ser
here's what I have so far, but didn't seem to work. thanks again
@echo off
for /f %%a in ('dir /b %USERPROFILE%\Desktop\serv
call:MoveThisFile %%a
)
goto:EOF
:MoveThisFile
set file=%1
set node=%file:~0,4%
rem Comment out the following two lines when you're ready to run this for real
echo if not exist %USERPROFILE%\Desktop\serv
echo move %USERPROFILE%\Desktop\serv
rem Remove the "rem" comments from these next two lines when you're ready to run this for real
if not exist %USERPROFILE%\Desktop\serv
move %USERPROFILE%\Desktop\serv
goto:EOF
What kind of error message(s) did you get?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maybe you need to wrap these in quotes?
Also, does that ending "." need to be removed?
%USERPROFILE%\Desktop\serverB\%node%
%USERPROFILE%\Desktop\serverA\%file%
i.e."%USERPROFILE%\Desktop\serverB\%node%"
"%USERPROFILE%\Desktop\serverA\%file%"
Also, does that ending "." need to be removed?
move \\serverA\clientPDFs\%file% \\serverB\client\%node%\.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FYI, vlsllp, I changed the code a little (above), adding double-quotes in case of any spaces and adding error checking. I tested it with files I created,and it seems to work okay.
Open in new window