Help with moving Files into unique Folders

February 26, 2013 at 18:52:50
Specs: Windows 7
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.

See More: Help with moving Files into unique Folders

Report •

February 26, 2013 at 19:03:27
The million dollar question is: where are the ssns coming from? The rest seems fairly straighforward. If they are in a spreadsheet or database, they could be exported to text. Probably from PDF as well.

Report •

February 27, 2013 at 05:54:39
The SSN's will be coming from a database
which I've exported into an excel file

Report •

February 27, 2013 at 11:44:56
Ok, but batch can't do excel, it would have to be exported to text for batch to have access to that information. If you decide to go that route, please post a sample of the output (text export, with obfuscated data, of course. no real names or ssns.)
Two or three lines would be sufficient.

Report •

Related Solutions

Ask Question