Similiar problem as previously solved question here - Batch create folders based on part of file name and move files into that folder
QUESTION: I have 15k files that I want to extract the first word from file name to create a folder, then move all those respective files into the folder.
This is driving me crazy trying to figure out!!!
**EXAMPLE: **Using the files below, I want all files beginning with PTC to move into a new folder called PTC, then the same process with files beginning with PRIORITY.
- PTC-Affiliate Digital Asset Refresh (160x600)
- PTC-Affiliate Digital Asset Refresh (160x600)2
- PTC-Affiliate Digital Asset Refresh (160x600)3
- PRIORITY-Affiliate Digital Asset Refresh (160x600)
- PRIORITY-Affiliate Digital Asset Refresh (160x600)2
- PRIORITY-Affiliate Digital Asset Refresh (160x600)3
I tried revising existing code (below), but am running into 2 issues:
- File names use spaces, not underscore - how do I denote that in the code?
- When I rename a test file using underscores instead of spaces, the code below will create the folder, but not move the actual files.
CODE I AM TRYING TO EDIT TO DO WHAT I WANT:
@ECHO OFF
SETLOCAL
SET "sourcedir=C:\[directory\]"
PUSHD %sourcedir%
FOR /f "tokens=1,2,3,4 delims=-" %%a IN ('dir /b /a-d "*\_*_\*_*\_*"') DO (
MD %%a 2\>nul
MOVE "%%a\_%%b\_%%c\_%%d\_%%e" .%%a\\ 2\>nul
)
POPD
GOTO :EOF
Any help or suggestions would be VERY welcomed.
Thank you!
I tried revising existing code (below), but am running into 2 issues:
- File names use spaces, not underscore - how do I denote that in the code?
- When I rename a test file using underscores instead of spaces, the code below will create the folder, but not move the actual files.
I am not able to solve for either of these issues.