View Full Version : Batch Programming Help

02-27-2013, 03:47 AM
Ok so here is the scenario. I have many pdf files where each file corresponds to 1 person. I need to move these files into a unique folder for each person. This Folder will be titled "Last Name (Last 4 Digits of SSN)". So here is how the folder looks now...


I need the .bat file to then put those files into their own folder
Rivera 1234
Jacobs 2345
Knoblauch 3456

I know somewhere I'm going to need an sql statement to place the file within the correct folder. My code now creates folders with the same name as the pdf file.

@echo off

REM Loop through every file in this folder
REM Excluding this batch file!

for /f "delims=" %%A in ( ' dir /b /a-d ^| find /v "%~nx0" ' ) do (

REM If a folder with the same base name
REM does not exist, create it
if not exist "%%~nA" md "%%~nA"

REM Move the file into the folder
REM and show message to user
echo Moving file: %%A to folder: %%~nA
move "%%A" "%%~nA"

REM Complete
echo Done

I found this code online and don't know how to completely decipher it so any help with that is also appreciated.

02-27-2013, 08:33 PM
the SSN's are in a spreadsheet