Page 1 of 1
Help please to link two simple commands
Posted: 30 Jan 2013 02:49
by dobbies
Hi
I run a webcam that takes an image every 5 seconds within daylight hours and creates around 6000 images throughout the day. When the webcam shuts down I have two batch files that help me sort these files out.
The first file is called (sort.bat) which removes every 20th file from a folder called (alldayvideo) and puts them in a folder called (temp)
Sort.bat...
Code: Select all
@echo off
set Counter=0
for %%f in (c:\alldayvideo\*.jpg) do call :p "%%f"
:p
set /a Counter+=1
set /a X=Counter %% 20
if %X%==0 move %1 C:\temp
The second file (delete.bat) deletes the remaining unwanted files from the (alldayvideo) folder.
Delete.bat...
Code: Select all
@echo off
for %%F in (c:\alldayvideo\*.jpg) do del "%%F"
I run both these files seperatley each day (one after the other) and they work just fine, but I wondered if somebody could offer me a code to do the same job but from just one file.
I've tried doing this myself but I get some odd results.
Any help would be appreciated.
Thanks
Re: Help please to link two simple commands
Posted: 30 Jan 2013 03:04
by shirulkar
This will work
@echo off
set Counter=0
for %%f in (c:\alldayvideo\*.jpg) do call :p "%%f"
del c:\alldayvideo\*.jpg
Exit /b
:p
set /a Counter+=1
set /a X=Counter %% 3
if %X%==0 move %1 c:\temp
Exit /b
Re: Help please to link two simple commands
Posted: 30 Jan 2013 03:04
by shirulkar
in above post just replace 3 with 20 . for testing purpose i used 3
Re: Help please to link two simple commands
Posted: 30 Jan 2013 03:55
by shirulkar
sorry man in above code i forgot to sort the file.
below code will work fine please use it.
Code: Select all
@echo off
set Counter=0
for /f "tokens=*" %%f in ('DIR /b /s /O:D c:\alldayvideo') do call :p "%%f"
del c:\alldayvideo\*.jpg
Exit /b
:p
set /a Counter+=1
set /a X=Counter %% 3
echo %1
if %X%==0 move %1 c:\tmp
Exit /b
Re: Help please to link two simple commands
Posted: 30 Jan 2013 05:27
by dobbies
Thank you very much for your prompt reply Shirulkar.
The code works perfectly and makes my life a little easier.
cheers
Re: Help please to link three simple commands
Posted: 30 Jan 2013 14:15
by dobbies
Hi
@echo off
set Counter=0
for /f "tokens=*" %%f in ('DIR /b /s /O:D c:\alldayvideo') do call :p "%%f"
del c:\alldayvideo\*.jpg
Exit /b
:p
set /a Counter+=1
set /a X=Counter %% 3
echo %1
if %X%==0 move %1 c:\tmp
Exit /b
After that great response from Shirulkar, could I add yet another command to the sequence to complete my jpg storage?
The final code to add is...
Code: Select all
set name=%DATE:/=_%
mkdir C:\wdisplay\alldayvideostorage\%name%
move c:\wdisplay\alldayvideostorage\*.jpg c:\wdisplay\alldayvideostorage\%name%
Many thanks
Re: Help please to link two simple commands
Posted: 30 Jan 2013 16:09
by abc0502
If You need to put the previous commands to shirulkar's code, this should work:
Code: Select all
@Echo OFF
Set Counter=0
For /F "tokens=*" %%f in ('DIR /b /s /O:D "C:\AllDayVideo"') Do Call :p "%%f"
Del "C:\AllDayVideo\*.jpg"
Set "name=%DATE:/=_%"
MKDIR "C:\wdisplay\alldayvideostorage\%name%"
Move "C:\wdisplay\alldayvideostorage\*.jpg" "C:\wdisplay\alldayvideostorage\%name%"
Exit /b
:p
set /a Counter+=1
set /a X=Counter %% 3
echo %1
if %X%==0 move %1 c:\tmp
Exit /b
This is NOT TESTED
Re: Help please to link two simple commands
Posted: 30 Jan 2013 22:49
by shirulkar
Hi dobbies
Just one question c:\wdisplay\alldayvideostorage\*.jpg contains all the files or contain only 20th,40th,.... file? OR "c:\wdisplay\alldayvideostorage\%name%" you want to store all files or only 20th,40th.....file?
Re: Help please to link two simple commands
Posted: 31 Jan 2013 02:13
by dobbies
Thanks you both abc0502 & shirulkar for your replies.
I have yet to test the code from abc0502 which I'll be doing shortly and post the result.
In answer to shirulkar.
OR "c:\wdisplay\alldayvideostorage\%name%" you want to store all files or only 20th,40th.....file?
It's the ["c:\wdisplay\alldayvideostorage\%name%" where I want to store the remaining 20th,40th, 60th & so on.....file].
Many thanks
Re: Help please to link two simple commands
Posted: 31 Jan 2013 02:34
by shirulkar
Hi dobbis,
following code will store 20th,40th,60th.... file directly in the require folder that is "c:\wdisplay\alldayvideostorage\%name%"
Code: Select all
@echo off
set Counter=0
set name=%DATE:/=_%
mkdir C:\wdisplay\alldayvideostorage\%name%
for /f "tokens=*" %%f in ('DIR /b /s /O:D c:\alldayvideo') do call :p "%%f"
del c:\alldayvideo\*.jpg
Exit /b
:p
set /a Counter+=1
set /a X=Counter %% 3
echo %1
if %X%==0 move %1 c:\wdisplay\alldayvideostorage\%name%
Exit /b
Re: Help please to link two simple commands
Posted: 01 Feb 2013 05:22
by dobbies
I tried the code from (adc0502) and for some reason after executing the batch file I was left with two empty folders, both (alldayvideo) & (alldayvideostorage).
I then tried yours shirulkar and it worked perfectly.
Thank you so much guys for your time and help.
Dobbies
UK