|
Answer» I can't fight this battle anymore alone so I'm turning to this forum for help.
Objective: To create a batch file that would - for each directory, DELETE the oldest file in the directory if the number of files is greater than 2. I would also like to log the date and which directory/file is being deleted into a simple txt file.
This will be run as a scheduled JOB on an XP Pro workstation every day as part of an attempt to keep "data backup files" from FILLING up an external USB drive.
I've got the snippets of code and can place them into "For" and "If" loops but I just can't seem to get them linked TOGETHER so the variable is passed to the next command. I almost got it to work but it would choke on the "|" (pipe) command or I'm sure I had a single/double quote in the wrong spot. After I was done it must have been 30 lines of code and created a dozen tmp files - scary!
Here are the snippets so you don't have to recreate them.
echo off setlocal EnableDelayedExpansion
REM enumerates directories dir /A:D /B
REM counts number of .tib files in a directory dir folder1\*.tib /B | find /v /c "::"
REM sorts .tib files (newest to oldest) in a directory dir folder1\*.tib /B /O:-D
Any help is appreciated, Joni
BTW: This script will do what Acronis True Image said it would do as part of its feature-rich product - Yeah, still waiting Acronis!!See here (example 4) for a vbscript, if you can use it.It looks like example 4: "Copy oldest modified file to Destination" comes closest to my needs but considering I'm worse at VB than I am at simple batch commands, I may be in the same boat in trying to tie in my other needs. I'll work on this tonight and report back. Thanks for the reply! Well, I can stumble through on what the code will do when run but I'm not sure how to compile it. I don't have time to learn a NEW language now but thanks for the examples anyway - I'm sure I'll use them in the future.
|