Page 1 of 1

Create Folder Based on Filename + Subfolders + Move Files

Posted: 27 May 2014 14:23
by nolimits76
Hey all, new to this place. Hoping you can help me with a work task. We are re-organizing the way our files are organized and have several thousand items that need work. This is something I'd like to automate.

I have (3) primary goals:

1. Create a folder name based on the file name. File name can vary in length, but typically in this format: 12345 - Project Name - City, ST.xls

2. Once the new folder name is created, create (4) subfolders called: Quote, Submittals, Cut Sheets & Correspondence.

3. Move original file (12345 - Project Name - City, ST.xls) and place inside the Quote folder.

No idea where to start. Please help. Thanks.

Re: Create Folder Based on Filename + Subfolders + Move File

Posted: 27 May 2014 15:02
by Squashman
Could you clarify bullet point 1 please? Based on the filename what do you want the base folder name to be?

Re: Create Folder Based on Filename + Subfolders + Move File

Posted: 27 May 2014 15:17
by nolimits76
Squashman wrote:Could you clarify bullet point 1 please? Based on the filename what do you want the base folder name to be?


Absolutely.

Folder name needs to duplicate entire file name sans the file extension. So in the example, the file name is 12345 - Project Name - City, ST.xls and I would need the folder name to be 12345 - Project Name - City, ST.

Re: Create Folder Based on Filename + Subfolders + Move File

Posted: 27 May 2014 21:33
by foxidrive
Test this in a copy of your folder tree.

Code: Select all

@echo off
for /f "delims=" %%a in ('dir /b /s /a-d *.xls ') do (
md "%%~dpna" 2>nul
md "%%~dpna\Quote" 2>nul
md "%%~dpna\Submittals" 2>nul
md "%%~dpna\Cut Sheets" 2>nul
md "%%~dpna\Correspondence" 2>nul
move "%%a" "%%~dpna\Quote" >nul
echo processed "%%a"
)
echo done
pause