Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to have a batch file that moves ".doc" files to a folder. The trick is that i have three user folders named Mark, Luke and John that I want these files to go to. Example, aa.doc is in a folder and it moves it to marks folder. Then when the next files aa1.doc comes in it moves it to luke's folder. Next file moves to John folder and this process repeats giving out files evenlly amongst the three user folders

Does anyone know how to do this?

share|improve this question
Will the round robin tracking need to persist between runs? Or can the round robin begin again with mark? – BrianAdkins Aug 7 '13 at 12:48

try this:

@echo off &setlocal
SET "target0=Marcella"
SET "target1=Lucca"
SET "target2=Daniella"

FOR %%A IN (*.doc) DO (
    SET /a counter+=1
    SET /a pointer=counter%%3
    SET "file=%%~A"
    CALL SET "target=%%target!pointer!%%"
    ECHO MOVE "!file!" "!target!"
share|improve this answer
ECHO MOVE "!file!" is this were I put in the file directory? – Alvin Aug 14 '14 at 18:13
Marcella, Lucca and Daniella are the target subfolders. You may set the source folder by a cd command: cd /d X:\Users\Me\Doc Files. – Endoro Aug 17 '14 at 9:42

Something like this:

@echo off
Rem allow for reusable variables

Set mark=0
Set luke=1
Set david=2

Rem drawing from your example
set prefix=aa

for /f "usebackq tokens=*" %%i in (`dir /b *.doc`) do (
        Rem strips file extension

        set file=%%~ni 


        Rem extracts numeric substring

        set num=%file:%~prefix%=%


       Rem Divide num by 3 and return remainder

       set mod=(%num%) % 3
       if %mod%==%mark% (move %filename% Mark)
       if %mod%==%luke% (move %filename% Luke) else (move %filename% David)

exit /b

This may require tweaking for your exact needs, but this will put you on track.

share|improve this answer

Your Answer


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.