| 1. |
Solve : create folders based on part of filename? |
|
Answer» I would appreciate some help on a batch i am trying to make which takes a bulk of files in a folder (ebook/video/music collection) and create folders based on a variable length first part of the filename (i.e. author name). for /f "delims=" %%A in ('dir /b /a-d ^| find /v "%~nx0"') do (That works and takes care of not having to WORRY about the spaces. I was trying to do it all in a single FOR LOOP. But the nested for loop definitely fixes all the concerns I had.Many thanks for the very quick reply and solutions. I did study an example in a previous topic with a similar question which resulted in a batch file calling a VBScript. As i recall also provided by Salmon Trout ;-) Again your solution works like a charm !! Now for me to break it down and actually learn from it ;-p Thanks are given to both for your efforts. You guys are great, keep it up !Quote from: Sunray on June 22, 2012, 02:29:27 PM Now for me to break it down REM use dir to GET each full filename, pipe through find to exclude this batch file) for /f "delims=" %%A in ('dir /b /a-d ^| find /v "%~nx0"') do ( REM break filename into 2 tokens: 1. everything before the first dash 2. everything after it REM we only need the first one for /f "tokens=1* delims=-" %%B in ("%%A") do ( REM first token is author name REM if folder of that name does not exist, create it if not exist "%%B" md "%%B" REM if this file is not already in the folder, move it there if not exist "%%B\%%A" move "%%A" "%%B" ) ) |
|