Need Help with Refining a Batch File. RRS feed

  • Question

  • I have a "black box" unit that will be installed in a vehicle, which records digital video onto an SD Card.

    The black box unit records in three-minute segments, creating and automatically naming
    the files; Windows automatically gives them a time/date stamp.

    Once the memory capacity of the SD Card is reached (approximately 12 hours), the black box begins overwriting the earliest time/date stamped files. The black box is 'always on', so it records 24/7.

    I plan, at the end of each day to copy/archive onto a computer's internal slave drive all of the DVR recordings off the SD Card from that day, but only those files that were created between 07:00 (AM) and 17:00 (PM).

    Once the task of copying/archiving the files is completed: (A) All the data files contained within the
    folder "EventList" on the SD Card are to be deleted; then (B) the entire folder and files contained in "FileList_ ? [date/time]" (e.g., FileList_20101117_191021) are also to be deleted.

    Therefore, I'm trying to create a batch file that will accomplish the following tasks:

    1) Create a new subfolder on a PC's internal fixed slave drive [E:\], and name it with the current day's date (e.g., 11192010).

    2) Copy the only those folders and files on the SD Card [F:\], created each day between 07:00 and 17:00, to the newly-created subfolder on the fixed slave drive [E:\].

    3) Delete all the files within a folder titled "EventList" on the SD Card [F:\], so that it becomes an empty folder.

    4) Completely delete the second folder on the SD Card, which is automatically created/named each day by the "Black Box" (e.g., "FileList_20101117_191021"); this hardware-generated name is a combination of
    the date and time.

    I believe I've been able to create (with much assistance) a batch file that accomplishes all four tasks, with the exception of only copying only those files created on the day between 07:00 and 17:00. Here's what I have so far:


    @echo off
    for /F " tokens=1,2,3* delims=/, " %%i IN ('date /T') DO (
    set CUR_DAY_OF_WEEK=%%i
    set CUR_MONTH=%%j
    set CUR_DAY=%%k
    set CUR_YEAR=%%l)

    for /F " tokens=1,2,3* delims=:, " %%i IN ('time /T') DO (
    set CUR_HOUR=%%i
    set CUR_MIN=%%j
    set AM_PM=%%k)

    MD "e:\blackbox\ford2000\%CUR_MONTH%%CUR_DAY%%CUR_YEAR%

    xcopy "f:\" "e:\blackbox\ford2000\%CUR_MONTH%%CUR_DAY%%CUR_YEAR%" /D /E /C /R /I/K /Y

    echo y | del f:\EventList\*.*

    @echo off & setLocal EnableDELAYedeXpansion

    for /f "tokens=* delims= " %%a in ('dir/b/s/ad f:\filelist*.*') do (
    xcopy %%~DPNa e:\%%~Na\ /s
    rd /s /q %%a


    If it is possible to do so, can anyone please help me restrict the xcopy process to only those folders/files created on the day between 07:00 and 17:00? I would be greatly appreciative of the assistance, as it would help save hard disk space (not to mention copying time) by not archiving those folders/files created outside of the aforementioned time parameter.


    Dina Miles
    Friday, April 22, 2011 3:31 PM