2

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:

00-00001.pdf
00-00002.pdf
00-00003.pdf

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:

D:.
├───00-00000
├───00-01000
├───00-02000
├───00-03000
├───00-04000
├───00-05000
├───00-06000
├───00-07000
├───00-08000
├───00-09000
├───00-10000
├───00-11000

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-00000
│       00-00001.pdf
│       00-00002.pdf
│       00-00003.pdf
│       00-00004.pdf
...
│       00-00997.pdf
│       00-00998.pdf
│       00-00999.pdf
│       
├───00-01000
│       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

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

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

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.