1

I want to delete the oldest and second eldest folder from a drive using a Windows Command Line script.

This is running from BackupAssist, which only supports windows command line commands/DOS in the GUI for pre or post-backup scripts. I'd rather not write a command line to call into a Powershell script.

Thanks

1 Answer 1

2

This will find the oldest and next oldest directories in the current directory. Comment out the echo commands and uncomment the rd commands to make it functional.

@echo off
rem cmd file to delete oldest and second oldest directories
setlocal enabledelayedexpansion
for /F "delims=" %%i in ('dir /b/ad-l/o-d') do @set nextoldest=!oldest! & SET oldest=%%i
echo %oldest%
echo %nextoldest%
rem rd /s/q %oldest%
rem rd /s/q %nextoldest%

If you want to make it look at the whole drive, change the dir command to look like this:

dir /b/ad-l/o-d/s \

That will take a long time.

Note that I excluded junction points with -l.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .