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:

  1. scan folder
  2. capture whatever. in example above, captures: "bob - test name"
  3. create folder called whatever. here, "bob - test name"
  4. moves files has whatever string folder.
  5. 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"     ) ) 

sed


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -