Batch File to Move Files with Same Beginning String to a Folder with That String Name -
so have set of files this:
bob - test name - 1.txt bob - test name - 2.txt bob - test name - 3.txt sam- foo name - 1.txt sam- foo name - 2.txt sam- foo name - 3.txt phil - 1.txt phil - 2.txt phil - 3.txt phil 2 - 1.txt phil 2 - 2.txt phil 2 - 3.txt
simply, pattern this:
[whatever] - #.txt [whatever](space)-(space)(number).extension
i following:
- scan folder
- capture whatever. in example above, captures: "bob - test name"
- create folder called whatever. here, "bob - test name"
- moves files has whatever string folder.
- and repeat 2-4 through files.
so far, have tried, have failed. not knowing how troubleshoot or see batch doing, shooting in wind.
i extension agnostic have various file types (mp3, etc) scenario (set extension @ beginning of batch file).
@echo off &setlocal set "startfolder=c:\test\test" cd /d "%startfolder%" %%x in (*.txt) ( /f "delims=" %%a in ('echo(%%~nx^|sed -r "s/^(.*)\s-\s[0-9]+$/\1/"') ( if not exist "%%~a\" md "%%~a" move "%%~x" "%%~a" ) )
Comments
Post a Comment