Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have some files

07-01.jpg
07-02.jpg until
07-48.jpg


37-01.jpg
37-02.jpg
37-03.jpg until37-48.jpg

I want to create folder

07, 08.... ,37

and then move multiple files

07-01.jpg, 07-02.jpg, 07-03.jpg into folder 07
08-01.jpg, 08-02.jpg, 08-03.jpg into folder 08
37-01.jpg, 37-02.jpg, 37-03.jpg into folder 37
etc

how would a batch script look like to acchieve this?

thanks

share|improve this question
    
It is unlikely that a batch script exists that does exactly this, so you would need to write one. –  Paul Sep 25 '13 at 4:36
add comment

2 Answers

No batch file needed:

for %F in (*-*.jpg) do @for /f "delims=-" %A in ("%F") do @md "%A" 2>nul&move /y "%F" "%A" >nul

Double up the percents if used within a batch script.

share|improve this answer
add comment

This should work:

@echo off
setlocal enableextensions enabledelayedexpansion
rem parameter 1: first prefix (e.g 7)
rem parameter 2: last prefix (e.g 37)
rem parameter 3: max counter (e.g. 48)
FOR /L %%A IN (%1,1,%2) DO (
    rem arrange the padding
    set pre=0%%A
    set pre=!pre:~-2!
    rem create the folder
    mkdir !pre!
    FOR /L %%B IN (1,1,%3) DO (
        rem arrange the padding
        set num=0%%B
        set num=!num:~-2!
        rem file name
        set curr_file=!pre!-!num!.jpg
        rem ECHO !curr_file!
        move !curr_file! !pre!
    )
)

Save in a batch file (e.g. store_files.bat) and invoke it with proper params:

store_files.bat 7 37 48

-

Edit: the solution of dbenham is more elegant.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.