I wonder if anyone could please spare the time and energy to help me?
I'm new to batch files; only programming languages I know are HTML and PHP. I wanted to sort the 400 or so photos of my son by the month and year they were taken, as the info is in the photo file. I googled and found a similar block of code used to sort images by size, and quickly learnt a little about batch file commands to alter it to grab the image month and year data instead, and then create folders using the month and year as the folder name, and sort the files into the respective folders.
Anyway, I found a flaw: after creating a file containing the image info, this code grabs the date and month in numerical form:
for /f "tokens=3,4 delims=/" %%a in ('type %info% ^| find.exe /i "File date"') do (set /a month=%%a) & (set /a year=%%b)
I found it failed to grab the month sometimes, and after much googling and reading the set/? help, finally discovered the /a after set means it is treating numbers beginning with 0 as octals. Since 08 isn't an octal, it was failing when the month was 08. So, I removed the /a option and it now grabs 08 as it should, but doesn't do what it's supposed to do. It creates the folder with correct name (such as 08_2011) but doesn't move the image file into the folder. The CMD prompt just states "can't find specified path" or something like that. If I replace the /a after set, it works albeit without the month present, so folder name becomes "_2011".
Can anyone help? Why doesn't it just assign the data to a variable like PHP?!
Here's the whole code for anyone requiring it:
:: Temp-/Infofile path/name
:: Dimension file path/name
set iview=C:\Program Files\IrfanView\i_view32.exe
:: File extensions
set filext=*.jpg *.tif
for %1 %%a in (%filext%) do call :EXTRACT "%%a"
"%iview%" %1 /info="%info%"
for /f "tokens=3,4 delims=/" %%a in ('type %info% ^| find.exe /i "File date"') do (set month=%%a) & (set year=%%b)
echo File: %~1 >> "%dims%"
echo Month: %month% >> "%dims%"
echo Year: %year% >> "%dims%"
if exist %date% (echo Moved to existing folder >> "%dims%") & (move "%~1" "%date%\") else (echo Moved to new folder %date% >> "%dims%") & (MD %date%) & (move "%~1" "%date%\")
echo. >> "%dims%"
if exist %info% del %info%