Batch file needed to auto delete old folders.

Discussion in 'Software' started by ArchAngel, Nov 19, 2005.

  1. ArchAngel

    ArchAngel Sergeant

    Hopefully this is the right place and somebody can help.

    I am running WinXP on several computers at work. We put cameras on each and they take pictures every 10 seconds. The computers reboot every day. The pictures are stored in a folder called Gallery. I have a batch file that creates a new folder in the Gallery folder and names it the current date (ie 11192005). It then copies all of the pictures in the Gallery folder into that sub-folder. I would like a batch file to automate deleting the oldest folder after 2 months or when there is so much space left on harddrive. Yes, there is plenty of storage on each computer.

    Thanks,
    Mike
     
  2. BrokenArrows

    BrokenArrows Sergeant

    A batch file for this would probably be hard to do but would probably be easy enough in c/c++ or java. You could set it to check the dates etc every time the pc reboots.

    As for when the harddrive is full i dont know. But i dont think it would be possible in a batch file.
     
  3. goldfish

    goldfish Lt. Sushi.DC

    If you wanted to stay away from compiled solutions, you could always try a bit of WMI/VB scripting. That gives you the power of VB script with the convinience of a batch file.
     
  4. ArchAngel

    ArchAngel Sergeant

    Yes, it is possible in a batch file. Here is one that I got off a website, but can't get it to do exactly what I want.

    setlocal ENABLEEXTENSIONS
    for /f "usebackq tokens=1-10" %%a in (`dir /-p /-s /-c C: ^| findstr /i /C:" Bytes Free"`) do set FreeSpace=%%c
    if %FreeSpace% LEQ 10000000000 ("tokens=2" %%a in 'dir /ad /od "D:\temp"') do (if NOT "%%a"=="" rd /s /q "%%a" goto jumpOut)
    )
    :JumpOut
    ::Dummy line - leave in to keep error from happening
    )


    It will do the freespace comparison, but I can't seem to get the next line to delete the oldest folder/folders.
     
  5. Kaller74

    Kaller74 Private E-2

    Please try this! I believe it will do the trick:

    FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :s_fixdate %%G %%H %%I %%J)
    goto :s_print_the_date

    :s_fixdate
    if "%1:~0,1%" GTR "9" shift
    FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (
    set %%G=%1&set %%H=%2&set %%I=%3)
    goto :eof


    :s_print_the_date

    rem if %mm%==2 set mm=14
    if %mm%==1 set /a mm=13

    set /a mon=%mm%-2

    :folder to delete
    rd /S /Q %mon%%dd%%yy%

    This is not 100% tested but

    Fast and bad

    t
     
  6. ArchAngel

    ArchAngel Sergeant

    That was even better than I was hoping for.

    Thanks Kaller! You're a genius.:)
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds