Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    deleting a file in a folder that is auto created with dates so only last item is deleted

    hello all i am looking for some help i have a program that auto creates a backup every 30 minutes but does not delete at interval and is filling up my hd i was wondering if anyone can help me i resurched a little and have tried to make a batch file in order to create a bat file this is what i have
    Code:
    @ECHO OFF
    
    
    for /f "usebackq delims== tokens= 2" %%i in (
      `WMIC OS GET localdatetime /format:value`
      ) do set localTime=%%i
    
    set "YYYY=%localTime:~0,4%"
    set "M=%localTime:~4,1%"
    set "MM=%localTime:~5,1%"
    set "D=%localTime:~6,1%"
    set "DD=%localTime:~7,1%"
    
    if %M%==0 set M=
    if %D%==0 set D=
    
    
    cd /d "~%~dp0"
    FOR /F "tokens=*" %%X IN ('dir .\%YYYY%\%M%%MM%\%D%%DD%\Backup-serversave-%YYYY%-%M%%MM%-%D%%DD%--*.zip /b /o:-d') DO set FILENAME=%%~X
    rem FILENAME now contains the last element
    if "%FILENAME%" neq "" DEL "%FILENAME%"
    pause
    however when it goes to delete the file it says it cannot find it is there anyone that can help me i would also like this to run at the same time as the program so every half hour or so if it is at all possable that way i dont get overloaded with the saves it would also be nice if there was a way to specify that it would not do anything if there were not at least say five files in the folder. thanks for anyone that can help me with this

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Gold Lounger
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    3,379
    Thanks
    7
    Thanked 205 Times in 195 Posts
    The line dir .\%YYYY%\%M%%MM%\%D%%DD%\Backup-serversave-%YYYY%-%M%%MM%-%D%%DD%--*.zip will look in the current directory for a folder named "2014\06\23" and a file "Backup-serversave-2014-06-23--*.zip".
    In a batch file if you need to look in a specific directory you need to specify the full path somewhere, not use just a relative path. You can do this by changing to the base directory using a "CD" command or add the base directory to your path specification. Alternatively, specify a base directory and use "dir /s" to search all sub-directories. Using the sub-directory option you can remove all the date determination code.
    See this post for some code samples.

    To schedule programs you should use "Task Scheduler".

    cheers, Paul

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •