I have a folder with more than a hundred thousand (100,000+) pdf files generated by a script that need to be moved to multiple folders based on the file name. The pdf files are all named like this: YY-nnnnn.pdf where YY is the year and nnnnn is the file sequence within a year, like this:


Each year contains about 25,000 files. I have generated the files for four years, I still have 6 years worth of pdfs to be generated.

I need to move these files to the server. The server has the following folder structure:


Each year can have up to YY-25000 folders. The files need to go each into their own folder based on the first five characters, like this:

│       00-00001.pdf
│       00-00002.pdf
│       00-00003.pdf
│       00-00004.pdf
│       00-00997.pdf
│       00-00998.pdf
│       00-00999.pdf
│       00-01000.pdf
│       00-01001.pdf
│       00-01002.pdf

I was thinking of using the RoboCopy utility but could not figure out how to script it correctly. Perhaps a small script will be required.

1 Answer 1


Found a solution based on this question. The batch file to move the files is this:

@echo off
    for /f "tokens=*" %%F in ('dir/b/a-d d:\temp\pdfprints\*.pdf') do call :sub1 %%F
    goto :eof

    set name=%1
    move d:\temp\pdfprints\%name% R:\%name:~0,5%000\%name%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .