Thursday, March 29, 2018

batch - Sorting files into folders, according a portion of the file name

I am looking to sort approximately 3,000 pdf files into their own folders. All 3,000 files are in one folder and follow the same format.




COURSE NAME - EMPLOYEEFIRSTNAME EMPLOYEELASTNAME


I have made all the folders, but now want to move the appropriate PDF document into the corresponding folder. I found this handy answer to get me started: How to sort files into folders, according to file names - Windows CMD.



This is what I'm currently trying to modify:



:: C:\Users\User\Desktop\Training Test.cmd
@Echo off

PushD "C:\Users\User\Desktop\Training Test"

For %%A in (*.pdf) do For /F "tokens=2,3delims=-." %%B in ("%%A") Do (
If Not exist "%%B" MD "%%B"
Move "%%A" "%%B"
)
PopD


What I'm finding is that it's creating a new folder with a space in front of the employee name. I have a folder named "EMPLOYEEFIRST EMPLOYEELAST", but its making a new folder of " EMPLOYEEFIRST EMPLOYEELAST" (note the space at the beginning).




I have also noticed that it creates a new folder for those employees with a hyphenated first or last name. EMPLOYEE-FIRST EMPLOYEE-LAST just turns into a new folder of " EMPLOYEE".



I'm very new to all of this. Is there a way of resolving the issues with the space in the folder name and hyphenated names?

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...