我有这个脚本,它是为了备份应用程序中的多维数据集而创建的。它每周六运行,并在应用程序文件夹中创建了一个子文件夹。由于空间要求,我不得不每周删除最旧的文件夹。我需要创建一个脚本来做到这一点。
这是备用代码:
:: Create folder for App Db if it does not exist
IF NOT EXIST %BACKUPDIR%%1"\"%2 GOTO MAKEDIR
GOTO CONT
:MAKEDIR
mkdir %BACKUPDIR%%1"\"%2
GOTO :CONT
:CONT
cd %BACKUPDIR%%1"\"%2
:: Get todays date
for /f "tokens=2,3,4 delims=/ " %%i in ('date /t') do (
set my_day=%%j
set my_month=%%i
set my_year=%%k )
set datestamp=%my_month%%my_day%%my_year%
::echo %datestamp%
:: Create date folder for app db
IF NOT EXIST %BACKUPDIR%%1"\"%2"\"%datestamp% GOTO MAKEDIRTIMEDATE
:MAKEDIRTIMEDATE
G:
cd %BACKUPDIR%%1"\"%2"\
mkdir %BACKUPDIR%%1"\"%2"\%datestamp%
:: Copy otl, csc, rul, rep files from App to Backup fodler
XCOPY %APPFOLDER%"\app\"%1"\"%2"\*.csc" %BACKUPDIR%%1"\"%2"\"%datestamp% /Y
XCOPY %APPFOLDER%"\app\"%1"\"%2"\*.rul" %BACKUPDIR%%1"\"%2"\"%datestamp% /Y
XCOPY %APPFOLDER%"\app\"%1"\"%2"\*.otl" %BACKUPDIR%%1"\"%2"\"%datestamp% /Y
XCOPY %APPFOLDER%"\app\"%1"\"%2"\*.rep" %BACKUPDIR%%1"\"%2"\"%datestamp% /Y
XCOPY %APPFOLDER%"\app\"%1"\"%2"\*.ind" %BACKUPDIR%%1"\"%2"\"%datestamp% /Y
cd %SCRIPTDIR%
:: Move data file from script dir to backupdir if data file exist If not exit out of code
IF NOT EXIST %SCRIPTDIR%%1"_"%2"_AllData.txt" GOTO EXIT
:END
MOVE %SCRIPTDIR%%1"_"%2"_AllData*.txt" %BACKUPDIR%%1"\"%2"\"%datestamp%
GOTO EXIT
:EXIT
exit /b
正如您所看到的,每周都会创建一个以创建数据为标题的新文件夹(即 102913)。该文件夹是应用程序的子文件夹。我需要一个脚本来删除最旧的文件夹。
到目前为止,我已经尝试过(使用测试文件夹):
FORFILES -p "C:\Oracle\test\New folder\new folder" -s -m *.rul /D -<7> /C "cmd IF @isdir == TRUE" /c del @path
和
forfiles -p "C:\Oracle\test\New folder\new folder" -s -m *.rul /D -<7> /C "cmd /c del @path"
任何建议都会很有用。