MacOS – Move files from a single folder to multiple folders, based on filename

automatorfindermacospdf

I have batch of files named A-01.pdf, A-02.pdf, B-01.pdf, B-02.pdf…. Then I have folder structure 01, 02, 03,…. How can I move all the files with 01 in there name to folder 01, all with 02 to folder 02 and so on?

There are a lot of scripts on the net but none of them seams to fit my case.

Best Answer

Assuming that these files are all in the same folder and the numbered folders are part of that folder as well, open Terminal and run

cd path/to/folder
for i in *.pdf; do
    mv "$i" "${i:2:2}/"
done