Help please to link two simple commands

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dobbies
Posts: 8
Joined: 30 Jan 2013 01:29

Help please to link two simple commands

#1 Post by dobbies » 30 Jan 2013 02:49

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

shirulkar
Posts: 40
Joined: 15 Jan 2013 23:53

Re: Help please to link two simple commands

#2 Post by shirulkar » 30 Jan 2013 03:04

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

shirulkar
Posts: 40
Joined: 15 Jan 2013 23:53

Re: Help please to link two simple commands

#3 Post by shirulkar » 30 Jan 2013 03:04

in above post just replace 3 with 20 . for testing purpose i used 3

shirulkar
Posts: 40
Joined: 15 Jan 2013 23:53

Re: Help please to link two simple commands

#4 Post by shirulkar » 30 Jan 2013 03:55

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

dobbies
Posts: 8
Joined: 30 Jan 2013 01:29

Re: Help please to link two simple commands

#5 Post by dobbies » 30 Jan 2013 05:27

Thank you very much for your prompt reply Shirulkar.

The code works perfectly and makes my life a little easier.

cheers 8)

dobbies
Posts: 8
Joined: 30 Jan 2013 01:29

Re: Help please to link three simple commands

#6 Post by dobbies » 30 Jan 2013 14:15

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

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Help please to link two simple commands

#7 Post by abc0502 » 30 Jan 2013 16:09

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

shirulkar
Posts: 40
Joined: 15 Jan 2013 23:53

Re: Help please to link two simple commands

#8 Post by shirulkar » 30 Jan 2013 22:49

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?

dobbies
Posts: 8
Joined: 30 Jan 2013 01:29

Re: Help please to link two simple commands

#9 Post by dobbies » 31 Jan 2013 02:13

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

shirulkar
Posts: 40
Joined: 15 Jan 2013 23:53

Re: Help please to link two simple commands

#10 Post by shirulkar » 31 Jan 2013 02:34

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

dobbies
Posts: 8
Joined: 30 Jan 2013 01:29

Re: Help please to link two simple commands

#11 Post by dobbies » 01 Feb 2013 05:22

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

Post Reply