I have a folder, C:\Users\User1\Desktop\Photos2019, with over 100 subfolders. In each of those subfolders are photos, all with varying names, except 3 photos in each are the same. I'd like to be able to create a 2 subfolders in each of the folders in the directory, one called 'Base' and one called 'Other', and have the 3 files the same in all moved into the 'Base' folder, and everything else moved into the 'Other' folder, something like below.



EDIT: So far I've been able to make a batch script that I can run in each folder, and it will do the job. It's when I try and add in /r for looping it, that it keeps running but doesn't do the job at all.

I have;

for %%a in (.) do md "Base"
for %%a in (.) do md "Other"
for %%a in (.) do move "Portrait.png" "Base"
for %%a in (.) do move "Landscape.png" "Base"
for %%a in (.) do move "Wide.png" "Base"
for %%a in (.) do move "*.png" "Other"

This is what I want I'm trying to run in each subfolder.

What would be the best way to do this? Thanks.

  • What have you tried? Super User isn't a scipt writing service. Lookup the commands cd,md,for,move in an open cmd window with an appended /? or online at ss64.com/nt – LotPings Aug 22 at 7:02
  • @lotpings I've edited the question to include what I have so far. – Samson92 Aug 22 at 8:33

Well I attest that the help of the for command needs several iterations of reading to be fully understood.

With an initial tree on my test RamDrive A:\

> tree /f a:\
    │       Landscape.png
    │       other.png
    │       Portrait.png
    │       Wide.png

This batch:

:: Q:\Test\2019\08\22\SU_1473860.cmd
@Echo off
set "StartDir=C:\Users\User1\Desktop\Photos2019"
Rem set "StartDir=A:\Test"

set "Base=Landscape.png Portrait.png Wide.png"

CD /D "%StartDir%"

for /d %%D in (*) Do (
    MD "%%~fD\Base"
    MD "%%~fD\Other"
    for %%B in (%Base%) Do Move "%%~fD\%%B" "%%~fD\Base\" >Nul 2>&1
    Move "%%~fD\*.png" "%%~fD\Other" >Nul 2>&1

yields this result:

> tree /F a:\
    │   ├───Base
    │   │       Landscape.png
    │   │       Portrait.png
    │   │       Wide.png
    │   │
    │   └───Other
    │           other.png
        │       Landscape.png
        │       Portrait.png
        │       Wide.png
  • That worked perfectly, thank you. – Samson92 Aug 22 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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