I just created my first Batch file, to organise my mobile phone pictures into folders (on Windows). It worked, I am just wondering if there is a more efficient way in coding this, as in its current form I would have to go through all possible combinations of years and months.
if exist 2018*.* md 2018
if exist 2019*.* md 2019
if exist 2020*.* md 2020
move 2018*.* 2018
move 2019*.* 2019
move 2020*.* 2020
if exist 2018\????_03_*.* md 2018\March
if exist 2018\????_04_*.* md 2018\April
if exist 2018\????_05_*.* md 2018\May
move 2018\????_04_*.* 2018\April
move 2018\????_05_*.* 2018\May
move 2018\????_03_*.* 2018\March
if exist 2019\????_03_*.* md 2019\March
if exist 2019\????_04_*.* md 2019\April
if exist 2019\????_05_*.* md 2019\May
move 2019\????_04_*.* 2019\April
move 2019\????_05_*.* 2019\May
move 2019\????_03_*.* 2019\March
if exist 2020\????_03_*.* md 2020\March
if exist 2020\????_04_*.* md 2020\April
if exist 2020\????_05_*.* md 2020\May
move 2020\????_04_*.* 2020\April
move 2020\????_05_*.* 2020\May
move 2020\????_03_*.* 2020\March
This uses the
????_??_*.*pattern and is allowed iffindstrdetects the 1st four characters as digits of a year in the 21st century with a following underscore. It then gets the month from the 2 digits in the 2nd token. It checks if directoryyear\month\exists and creates it if not exist. If directoryyear\month\exist, copies the file into the directory.forvariables:Ayear digitsBmonth digitsCremainder of filenameDmonth digits and nameEmonth digitsFmonth nameView
for /?for help with understanding aforloop.