0

OK, I just made this file mover and it moves the files with matching file names.

move "03 Extracted\Files\1 *.txt" "06 Edit Files\Files 1\"

This works great and this was easy.

But how do I move files that don't have matching names?

1 - dog.txt
5 - cat.txt
10 - birds.txt
45 - seats.txt
152 - rooms.txt

I would like to keep it simple. I'm thinking the easiest would be to read the numbers at the beginning of the file name.

move "03 Extracted\* - *.txt" "06 Edit Files\Files 1-9\"
move "03 Extracted\** - *.txt" "06 Edit Files\Files 10-99\"
move "03 Extracted\*** - *.txt" "06 Edit Files\Files 100-999\"

I want to move files based on the numbers in front of the filename, and into the right number folders.

How could this be written?

1 Answer 1

1

Sadly, with dir the wildcard ? means "zero or one character".
Gladly, with where, the wildcard ? means "exactly one character".
That helps with building matching patterns:

@echo off
setlocal 

set "folder=03 Extracted\Files"
for /f "delims=" %%a in ('where /r "%folder%" "? -*"') do ECHO move "%%a" "Files 1-9\"
for /f "delims=" %%a in ('where /r "%folder%" "?? -*"') do ECHO move "%%a" "Files 10-99\"
for /f "delims=" %%a in ('where /r "%folder%" "??? -*"') do ECHO move "%%a" "Files 100-999\"

NOTE: I "disarmed" the move commands by just echoing it. Remove the ECHO's when it does what you want.

Before:

D:.
│   test.bat
│
├───03 Extracted
│   └───Files
│          1 - dog.txt
│          10 - birds.txt
│          152 - rooms.txt
│          45 - seats.txt
│          5 - cat.txt

├───Files 1-9
│
├───Files 10-99
│
└───Files 100-999

After:

D:.
│   test.bat
│
├───03 Extracted
│   └───Files
├───Files 1-9
│       1 - dog.txt
│       5 - cat.txt
│
├───Files 10-99
│       10 - birds.txt
│       45 - seats.txt
│
└───Files 100-999
        152 - rooms.txt
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.