폴더를 삭제하는 코드가 있는데,이 경우 'n'개의 폴더를 제외한 모든 파일을 삭제합니다. 나는 10 개의 테스트 폴더와 거기에 이미 있던 1 개를 만들었습니다. 4를 제외하고 모두 삭제하고 싶습니다. 코드가 작동하면서 다른 폴더를 떠나는 것을 제외하고는 테스트 폴더 중 4 개를 남겨 둡니다. 삭제되는 것을 멈추는 배치 파일에서 체크되고있는 다른 폴더의 속성이 있습니까? 몇 주 전에 일을 통해 창안되었습니다. 여기 폴더 삭제를위한 배치 파일
내가 훔친 코드입니다 (하지만 정말 세부 사항을 이해하지 않습니다)에 대한rem DOS - Delete Folders if # folders > n
@Echo Off
:: User Variables
:: Set this to the number of folders you want to keep
Set _NumtoKeep=4
:: Set this to the folder that contains the folders to check and delete
Set _Path=C:\MyFolder_Temp\FolderTest
If Exist "%temp%\tf}1{" Del "%temp%\tf}1{"
PushD %_Path%
Set _s=%_NumtoKeep%
If %_NumtoKeep%==1 set _s=single
For /F "tokens=* skip=%_NumtoKeep%" %%I In ('dir "%_Path%" /AD /B /O-D /TW') Do (
If Exist "%temp%\tf}1{" (
Echo %%I:%%~fI >>"%temp%\tf}1{"
) Else (
Echo.>"%temp%\tf}1{"
Echo Do you wish to delete the following folders?>>"%temp%\tf}1{"
Echo Date Name>>"%temp%\tf}1{"
Echo %%I:%%~fI >>"%temp%\tf}1{"
))
PopD
If Not Exist "%temp%\tf}1{" Echo No Folders Found to delete & Goto _Done
Type "%temp%\tf}1{" | More
Set _rdflag= /q
Goto _Removeold
Set _rdflag=
:_Removeold
For /F "tokens=1* skip=3 Delims=:" %%I In ('type "%temp%\tf}1{"') Do (
If "%_rdflag%"=="" Echo Deleting
rd /s%_rdflag% "%%J")
:_Done
If Exist "%temp%\tf}1{" Del "%temp%\tf}1{"
서식이 엉망입니다. 문제를 수정하여 수정하십시오. –
@ 에코가 실제로 무엇을하는지 보려면 켜십시오. –