큐톤의 오래된 폴더 삭제
:: QTM C:\ oldMovie Clear
:: Auther INNER_YJKIM
@echo off
:start
@echo -Start C drive cleanup (%date% %time%)-
@echo.
goto getdeleteday
:: START get delete base date #######################################
:getdeleteday
::set sorage period
set storagePerid=25
:: today
for /f "tokens=1-3 delims=- " %%A in ('echo %DATE%') do (set YY=%%A&SET MM=%%B&SET DD=%%C)
:: test ( .bat yyyy mm dd perid)
if not "%1"=="" set storagePerid=%1
if not "%2"=="" set YY=%2
if not "%3"=="" set MM=%3
if not "%4"=="" set DD=%4
set /a DD=1%DD%-(100+%storagePerid%)
set /a MM=1%MM%-100
:: DD setting
if %DD% GTR 0 (
goto getdeleteday_end
) else (
set /a MM=%MM%-1
)
:: MM setting
if %MM% GTR 0 (
goto leap
) else (
set /a MM=12-%MM%
set /a YY=%YY%-1
goto leap
)
:leap
set /a TT=%YY%/4
set /a TT=%TT%*4
if %YY% neq %TT% goto mon%MM%
if %MM% neq 2 goto mon%MM%
set /a DD=29
goto getdeleteday_end
::31days
:mon1
:mon3
:mon5
:mon7
:mon8
:mon10
:mon12
set /a DD=31+%DD%
goto getdeleteday_end
::30days
:mon4
:mon6
:mon9
:mon11
set /a DD=30+%DD%
goto getdeleteday_end
::etcdays
:mon2
set /a DD=28+%DD%
goto getdeleteday_end
:getdeleteday_end
set /a DD=%DD% + 100
set DD=%DD:~1,2%
set /a MM=%MM% + 100
set MM=%MM:~1,2%
set beforeday=%YY%%MM%%DD%
@echo #########################################################
@echo Storage period %storagePerid% days
@echo Deleted before %beforeday:~0,4%-%beforeday:~4,2%-%beforeday:~6,2% (not include this day)
@echo #########################################################
@echo.
goto cleanup
:: END get delete base date ######################################
:: START delete folder ###########################################
:cleanup
set drive_path=C:\IptvQueTone
set folder_name=device
:: move form IptvQueTone drive
if not exist "%drive_path%" (
@echo %drive_path% dose not exist
goto end
)
cd %drive_path%
goto usefoldername
:: delete by folder name
:usefoldername
set num=0
for /d %%i in (%folder_name%*) do (
if not "%%i"=="%folder_name%" (
for /d %%f in (%%i\*) do call :deletefolder %%i %%~nf
@echo.
)
)
goto end
:: (caller usefoldername)
:deletefolder
set pfolder=%1
set foldername=%2
set folderdate=%foldername:~0,4%%foldername:~5,2%%foldername:~8,2%
if %folderdate% LSS %beforeday% (
@echo \%pfolder%\%foldername% deleted..
rmdir /s /q %drive_path%\%pfolder%\%foldername%
)
exit/b
:: END delete folder #############################################
:end
@echo -End C drive cleanup (%date% %time%)-
'Language > OS Script' 카테고리의 다른 글
[bat] 날짜 계산 (오늘 기준 -n일) (0) | 2021.04.02 |
---|---|
[bat] 디스크 용량 로그 출력 (0) | 2021.04.02 |