hazyarc
hazyarc

Reputation: 13

Batch File To Dynamically Create New Directory Based on Date

I need assistance in adding functionality to my batch file that currently grabs a jpg from an IP camera every 5 minutes that will automatically create a new folder once midnight rolls around and start dumping new images there. Long story short, I'd like a folder named the current date with each day's images inside. Here's what I have so far:

wget -P C:\Cam -O imagenew.jpg "http://192.168.1.95:11000/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=root&pwd=password"
timeout /t 10
set SAVESTAMP=%DATE:/=-%@%TIME::=-%.jpg
set SAVESTAMP=%SAVESTAMP: =%
copy /Y imagenew.jpg F:\images\%SAVESTAMP%

This works flawlessly in placing the image with the appropriate timestamp in the F:\images directory. As stated above, I'd like to add logic that would automatically create a new directory inside F:\images with the current date (i.e. F:\images\4-16-15) and start dumping new images inside that new directory once midnight rolls around. Thanks!

Upvotes: 1

Views: 326

Answers (1)

Parag Doke
Parag Doke

Reputation: 863

Why not create the folder beforehand, and let wget download to it? Assuming you will save this as a batch file ...

set SAVESTAMP=%DATE:/=-%@%TIME::=-%.jpg
set SAVESTAMP=%SAVESTAMP: =%
for /f "tokens=2-4 delims=/ " %%A in (%date%) do set FolderName=%%C-%%A-%%B REM YY-MM-DD
wget -P C:\Cam\%FolderName% -O imagenew.jpg "http://192.168.1.95:11000/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=root&pwd=password"
timeout /t 10

Upvotes: 1

Related Questions