Chappers Posted June 29, 2011 Share Posted June 29, 2011 Hi, I wonder if anyone could please spare the time and energy to help me? 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: Thanks @echo off cls setlocal :: Temp-/Infofile path/name set info=%temp%\info.txt :: Dimension file path/name set dims=date.txt :: IrfanView set iview=C:\Program Files\IrfanView\i_view32.exe :: File extensions set filext=*.jpg *.tif for %1 %%a in (%filext%) do call :EXTRACT "%%a" goto :END :EXTRACT "%iview%" %1 /info="%info%" for /f "tokens=3,4 delims=/" %%a in ('type %info% ^| find.exe /i "File date"') do (set /a month=%%a) & (set /a year=%%b) echo File: %~1 >> "%dims%" echo Month: %month% >> "%dims%" echo Year: %year% >> "%dims%" set date=%month%_%year% 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%" goto :EOF :END if exist %info% del %info% endlocal Quote Link to comment https://forums.phpfreaks.com/topic/240668-batch-file-set-a-problem/ Share on other sites More sharing options...
Chappers Posted June 30, 2011 Author Share Posted June 30, 2011 No idea why, but removing the back slash from the end of the folder name variable %date% fixed it. So (move "%~1" "%date%\") became (move "%~1" "%date%"). Strange that with set /a it wasn't an issue, but without the /a, it suddenly was and caused 'specified path not found' errors. Quote Link to comment https://forums.phpfreaks.com/topic/240668-batch-file-set-a-problem/#findComment-1236762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.