1

I want to run a batch script that runs for month. The code is below. It processes loads of videos and sends their various outputs to various folders. The problem is if its running for a month unattended, the disk might be full. I want it to check if the disk is full and ontinue writing to another disk. It would be nice to have a log as well

`@echo off
    setlocal enabledelayedexpansion
    set EXE_FILE=E:\opencv\build\bin\Release\blobtrack_sample.exe
    set INPUT_PATH=E:\Glasgow\Test\
    set TRACKS_PATH=E:\Glasgow\Tracks\
    set OUTPUT_PATH=E:\Glasgow\Result\
    set COUNT=0
    pushd %INPUT_PATH%
    for %%f in (*) do if %%f neq %~nx0 (
        set /a COUNT+=1
        echo Processing %%f, track=%%~nf.txt, btavi=test!COUNT!%%~xf
        %EXE_FILE% fg=FG_0S bd=BD_CC bt=CCMSPF btpp=None bta=Kalman btgen=RawTracks track=%TRACKS_PATH%\%%~nf.txt FGTrainFrames=125 btavi=%OUTPUT_PATH%\%%~nf.avi %%f
    )
    popd`
Booboo
  • 45
  • 1
  • 5
  • 1
    What about just buying a disk that can keep up with the data you're producing? Storage space is cheap these days. – Joey Jul 25 '12 at 12:10

2 Answers2

0

Consider the following:

`@echo off
    set drive="E"
    set /A size=99
    FOR /F "tokens=1-5" %G IN ('dir ^| find "Dir(s)"') do set size=%I
    echo %size% > currentsize.txt
    echo %size% >> sizelog.log
    FOR /F "tokens=1-5" %G IN ('dir ^| find "currentsize.txt"') do set /A size=%J

REM SIZE LESS THAN 4 INDICATES LESS THAN 1024 Bytes left on the disk.
    IF %size% LSS 4 set drive="F"

    setlocal enabledelayedexpansion
    set EXE_FILE=%drive%:\opencv\build\bin\Release\blobtrack_sample.exe
    set INPUT_PATH=%drive%:\Glasgow\Test\
    set TRACKS_PATH=%drive%:\Glasgow\Tracks\
    set OUTPUT_PATH=%drive%:\Glasgow\Result\
    set COUNT=0
    pushd %INPUT_PATH%
    for %%f in (*) do if %%f neq %~nx0 (
        set /a COUNT+=1
        echo Processing %%f, track=%%~nf.txt, btavi=test!COUNT!%%~xf
        %EXE_FILE% fg=FG_0S bd=BD_CC bt=CCMSPF btpp=None bta=Kalman btgen=RawTracks track=%TRACKS_PATH%\%%~nf.txt FGTrainFrames=125 btavi=%OUTPUT_PATH%\%%~nf.avi %%f
    )
    popd`
mnmnc
  • 374
  • 3
  • 14
  • It is setting the variable 'drive' to initial letter E. Then it checks the output of the command dir. This command by default provides information about free space in the last line of the output. I take this line and divide it by spaces. The 3rd word contains a number of bytes left. I get this numer as variable and pass it to the file. Depending on the lenght of number you can assume how much space is left. if the output file will have a size less than 4 it will mean that the space left is a 3 digit number in bytes - which is very small. Than it changes the drive to F. – mnmnc Jul 26 '12 at 12:31
  • what if I want it to change to 'K' for instance, what parts of the code do i change – Booboo Jul 26 '12 at 13:10
  • You can check each time for free space on all available disks. Just instead of using command dir ^| FInd "Dir(S)" you will use dir C: ^| Find "Dir(s)" for each disk you want to check (Disk C in this example). Than repeat the checking code for each disk by nesting the IFs conditions and it will change the current available drive letter to the first available with free space on it – mnmnc Jul 26 '12 at 13:12
0

I found this code from this answer. I advise you to read all the answers there and you will find something to work with

save the folling in a batch file and run it. It will display the free bytes of C: drive. Use the variable in an IF condition to change the target save-to drive

@setlocal enableextensions enabledelayedexpansion
@echo off
for /f "tokens=3" %%a in ('dir c:\') do (
    set bytesfree=%%a
)
set bytesfree=%bytesfree:,=%
echo %bytesfree%
endlocal && set bytesfree=%bytesfree%
Community
  • 1
  • 1
Ahmad
  • 12,336
  • 6
  • 48
  • 88