Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Batch script to download and save picture

Hardware/software/hints and tips/discussion/webcam links etc
Post Reply
ironeagleuk
Posts: 322
Joined: Wed 02 Dec 2009 8:42 pm
Weather Station: Maplins N96GY (Watson W-8681)
Operating System: Windows 7 Home
Location: Folkestone, Kent, UK
Contact:

Batch script to download and save picture

Post by ironeagleuk »

For one of my weathercams I am using Webcam XP to upload pics to my website.

I want to reliably download the pic from my website, save it to a folder, and rename it with a time and date stamp.

I have found some code that sorts of does this, but I don't fully understand how it works.

The problem with it is that it does download the file, but only works when the time stamp for hour is in double figures...ie after 10am

Also it creates a new folder for every day, but after 24 hours it deletes the contents of the folder for some reason....it's wierd, and I can't understand why it's doing that. The folder remains, but as it downloads a picture with the same time stamp, it slowly deletes those files from yesterdays folder.

Here's the code I am using....as I said, am no expert, and just acquired it from the net, and was wondering if someone could look at it, and work out what is going on.....or give me a better alternative to do the job

Code: Select all

echo on
c:

cd\WebCams\Capture\Webcam2\

md %date:~-4,4%-%date:~3,2%-%date:~-10,2%
cd\

del c:\WebCams\Capture\Webcam2\%date:~-4,4%-%date:~3,2%-%date:~-10,2%\cam_1.jpg
cd\WebCams\Capture\Webcam2\%date:~-4,4%-%date:~3,2%-%date:~-10,2%
wget http://www.ironeagleuk.co.uk/cumulus/webcam/cam_1.jpg
cd\

cd\WebCams\Capture\Webcam2\%date:~-4,4%-%date:~3,2%-%date:~-10,2%\

ping -n 15 www.ironeagleuk.co.uk

ren cam_1.jpg cam_2_%time:~0,2%%time:~3,2%-%date:~-10,2%%date:~3,2%%date:~-4,4%.jpg

ping -n 15 www.ironeagleuk.co.uk

c:\camrename.bat

The ping command is just there to provide a 30 second pause
Richard

Image
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Re: Batch script to download and save picture

Post by sfws »

I do not understand your code sample, so I cannot help with that. Here are 2 alternatives if you don't get help from those who know.

When my non computer literate Mum was losing files, I installed http://download.cnet.com/AutoVer/3000-2 ... 98168.html to date stamp back ups of key files she was editing on her hard disc. Essentially, when running it automatically monitors selected directories for particular files changing, and backs those up. (The disadvantage is locking can stop it working).

I use http://sourceforge.net/projects/freefilesync/ for manual backing up of my key files on my computer - an option date time stamps files that are overwritten in the back up folder(s). This handles locked files, and can be run from a batch script.
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Batch script to download and save picture

Post by mcrossley »

I've put some remarks in to show what the script does...

Code: Select all

echo on
REM path to C: drive
c:

REM change directory to "\WebCams\Capture\Webcam2
cd\WebCams\Capture\Webcam2\

REM Assuming UK date format dd/mm/yyyy, creates a new sub-directory with current date - "yyyy-mm-dd"
md %date:~-4,4%-%date:~3,2%-%date:~-10,2%

REM change directory back to root
cd\

REM deletes "yyyy-mm-dd\cam_1.jpg"
del c:\WebCams\Capture\Webcam2\%date:~-4,4%-%date:~3,2%-%date:~-10,2%\cam_1.jpg

REM change directory to "\WebCams\Capture\Webcam2\yyyy-mm-dd"
cd\WebCams\Capture\Webcam2\%date:~-4,4%-%date:~3,2%-%date:~-10,2%

REM get the file
wget http://www.ironeagleuk.co.uk/cumulus/webcam/cam_1.jpg

REM change directory back to root
cd\

REM change directory to "\WebCams\Capture\Webcam2\yyyy-mm-dd" - again!
cd\WebCams\Capture\Webcam2\%date:~-4,4%-%date:~3,2%-%date:~-10,2%\

REM wait a bit
ping -n 15 www.ironeagleuk.co.uk

REM rename "cam_1.jpg" to "cam_2_hhmm-ddmmyyyy.jpg"
ren cam_1.jpg cam_2_%time:~0,2%%time:~3,2%-%date:~-10,2%%date:~3,2%%date:~-4,4%.jpg

REM wait a bit
ping -n 15 www.ironeagleuk.co.uk

REM ?presumably call this script again?
c:\camrename.bat
The problem with the hour is only a single digit before 10 and the script is hard coded for two digits.

I would change it to something like (untested!)...

Code: Select all

:: Isolate the variables to this instance of the script
setlocal

:: Get the date and time into variables
for /f "tokens=1-3 delims=/ " %%a in ("%date%") do set dy=%%a&set mo=%%b&set yr=%%c
for /f "tokens=1-2 delims=:. " %%a in ("%time%") do set hr=%%a&set mi=%%b

:: Change drive & directory to "C:\WebCams\Capture\Webcam2
cd /D C:\WebCams\Capture\Webcam2\

:: Create todays directory if it does not exist
md %yr%-%mo%-%dy%

:: Change path to "\WebCams\Capture\Webcam2\yyyy-mm-dd"
cd %yr%-%mo%-%dy%

:: Get the remote file
wget http://www.ironeagleuk.co.uk/cumulus/webcam/cam_1.jpg

:: Wait a bit
::ping -n 15 www.ironeagleuk.co.uk
:: Wait a bit - Better on Vista or later..
timeout /t 15

:: OR, better yet, wait for the wget program to finish rather than relying on a timeout, replace "wget" above with
::start /wait wget http://www.ironeagleuk.co.uk/cumulus/webcam/cam_1.jpg

:: Rename "cam_1.jpg" to "cam_2_hhmm-ddmmyyyy.jpg"
ren cam_1.jpg cam_2_%hr%%mi%-%dy%%mo%%yr%.jpg

:: Wait a bit
::ping -n 15 www.ironeagleuk.co.uk
:: Wait a bit - Better on Vista or later..
timeout /t 30

: End isolation of the variables to this instance of the script
endlocal

:: ?Presumably call this script again?
c:\camrename.bat
Last edited by mcrossley on Sun 04 Nov 2012 9:41 am, edited 5 times in total.
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Re: Batch script to download and save picture

Post by sfws »

(deleted)
Last edited by sfws on Mon 03 Aug 2015 10:58 am, edited 1 time in total.
ironeagleuk
Posts: 322
Joined: Wed 02 Dec 2009 8:42 pm
Weather Station: Maplins N96GY (Watson W-8681)
Operating System: Windows 7 Home
Location: Folkestone, Kent, UK
Contact:

Re: Batch script to download and save picture

Post by ironeagleuk »

That's great, thanks Mark....I have used the exact code you have posted above

I have it up and running, and is creating the files with the correct timestamps...will have to see what happens after midnight

but weirdly it's still deleting the files from the previous days folder :?

Also it's keeping instances of the downloaded file with a number at the end...will see if I can do something about that..solution added before the wget command:

Code: Select all

:: Delete any instance already existing of cam_1
del cam_1*.*
Richard

Image
ironeagleuk
Posts: 322
Joined: Wed 02 Dec 2009 8:42 pm
Weather Station: Maplins N96GY (Watson W-8681)
Operating System: Windows 7 Home
Location: Folkestone, Kent, UK
Contact:

Re: Batch script to download and save picture

Post by ironeagleuk »

Ok, I have discovered that the deleting of the file from the pervious days folder isn't related to the batch file at all....but I have no idea what could be deleting the files. It's almost as though it has a 24 hour life span and deletes itself after that. Is that possible?
Richard

Image
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Batch script to download and save picture

Post by mcrossley »

ironeagleuk wrote: but weirdly it's still deleting the files from the previous days folder :?
very odd, there isn't another copy of the script running in the background or something? Task scheduler?

PS. Cross posted with your post above.
ironeagleuk
Posts: 322
Joined: Wed 02 Dec 2009 8:42 pm
Weather Station: Maplins N96GY (Watson W-8681)
Operating System: Windows 7 Home
Location: Folkestone, Kent, UK
Contact:

Re: Batch script to download and save picture

Post by ironeagleuk »

mcrossley wrote:
ironeagleuk wrote: but weirdly it's still deleting the files from the previous days folder :?
very odd, there isn't another copy of the script running in the background or something? Task scheduler?

PS. Cross posted with your post above.
I have now discovered that it is when WebCamXP is running that the files get deleted ....no idea why though. There is no option in the software to stop it happening.
Think I'll have to contact the developer, or find another piece of software
Richard

Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Batch script to download and save picture

Post by beteljuice »

Also it's keeping instances of the downloaded file with a number at the end...will see if I can do something about that..solution added before the wget command:
There is nothing in the script to do that ! (ie. cam_1xxxxx.jpg).

However; If I remember correctly (from a long time ago) your software can - have you been playing and set it to create sequential pictures locally AND ftp single (fixed name) picture to web ?

This may also have something to do with deleting (duplicate) names as they occur even though you think they are in different directories.
Image
......................Imagine, what you will KNOW tomorrow !
ironeagleuk
Posts: 322
Joined: Wed 02 Dec 2009 8:42 pm
Weather Station: Maplins N96GY (Watson W-8681)
Operating System: Windows 7 Home
Location: Folkestone, Kent, UK
Contact:

Re: Batch script to download and save picture

Post by ironeagleuk »

beteljuice wrote:
Also it's keeping instances of the downloaded file with a number at the end...will see if I can do something about that..solution added before the wget command:
There is nothing in the script to do that ! (ie. cam_1xxxxx.jpg).

However; If I remember correctly (from a long time ago) your software can - have you been playing and set it to create sequential pictures locally AND ftp single (fixed name) picture to web ?

This may also have something to do with deleting (duplicate) names as they occur even though you think they are in different directories.
I think there was a problem with the timing of the download...I fixed it with the delete command, so it doesn't do it anymore.


But have a problem with the rename code in the script, as it's coming up with the following message now it's rolled over to a single number hour

Code: Select all

C:\WebCams\Capture\Webcam2\2012-11-04>ren cam_1.jpg cam_2_ 015-04112012.jpg
The syntax of the command is incorrect.
It's putting a space between the end of the filename text and the time stamp in the filename
Richard

Image
ironeagleuk
Posts: 322
Joined: Wed 02 Dec 2009 8:42 pm
Weather Station: Maplins N96GY (Watson W-8681)
Operating System: Windows 7 Home
Location: Folkestone, Kent, UK
Contact:

Re: Batch script to download and save picture

Post by ironeagleuk »

Have found the following code on the internet which seems to have fixed my single digit hour problem, but I guess I won't find out til 10am

Code: Select all

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
I have kept the original code as is, but instead of using %hr% as the hour variable, I am using %hour%

The code now looks like this:

Code: Select all

:: Isolate the variables to this instance of the script
setlocal

:: Get the date and time into variables
for /f "tokens=1-3 delims=/ " %%a in ("%date%") do set dy=%%a&set mo=%%b&set yr=%%c
for /f "tokens=1-2 delims=:." %%a in ("%time%") do set hr=%%a&set mi=%%b

:: Set variable for hour depending on whether it is single or a double digit
set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%


:: Change drive & directory to "C:\WebCams\Capture\Webcam2
cd /D C:\WebCams\Capture\Webcam2\

:: Create todays directory if it does not exist
md %yr%-%mo%-%dy%

:: Change path to "\WebCams\Capture\Webcam2\yyyy-mm-dd"
cd %yr%-%mo%-%dy%

:: Delete any instance already existing of cam_1
del cam_1*.*


:: Get the remote file
wget http://www.ironeagleuk.co.uk/cumulus/webcam/cam_1.jpg

:: Wait a bit
::ping -n 15 www.ironeagleuk.co.uk
:: Wait a bit - Better on Vista or later..
timeout /t 15

:: OR, better yet, wait for the wget program to finish rather than relying on a timeout, replace "wget" above with
::start /wait wget http://www.ironeagleuk.co.uk/cumulus/webcam/cam_1.jpg

:: Rename "cam_1.jpg" to "cam_2_hhmm-ddmmyyyy.jpg"
ren cam_1.jpg cam_2_%hour%%mi%-%dy%%mo%%yr%.jpg

:: Wait a bit
::ping -n 15 www.ironeagleuk.co.uk
:: Wait a bit - Better on Vista or later..
timeout /t 30

:: End isolation of the variables to this instance of the script
endlocal

:: ?Presumably call this script again?
c:\camrename2.bat

Richard

Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Batch script to download and save picture

Post by beteljuice »

No need for the echo statement ;)
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Batch script to download and save picture

Post by mcrossley »

ironeagleuk wrote:Have found the following code on the internet which seems to have fixed my single digit hour problem, but I guess I won't find out til 10am
.....
I did say it was untested, but I see the problem...

Code: Select all

for /f "tokens=1-2 delims=:." %%a in ("%time%") do set hr=%%a&set mi=%%b
should be...

Code: Select all

for /f "tokens=1-2 delims=:. " %%a in ("%time%") do set hr=%%a&set mi=%%b
Note the space before the first closing quote, as in the date statement.
Post Reply