-2

I am trying to delete all items NOT .aspx, but i wasn't sure how to do it. Right now i was just going through everything with

del /F *.html
del /F *.csproj
del /F *.ico

etc.

Is there a simpler command to just say: DELETE EVERYTHING in DIRECTORY NOT a FOLDER OR has an extension of .aspx

I cant seem to find a solution on the Internet which matches my question. I didn't know if DEL accepted Regex to be like /^.*(^\.aspx)$ or something

bash file says:

chdir C:\Users\william.francis\Desktop\Deploy\tmp
for /f "delims=ÿ" %a in ('dir /b /a-d ^| find /v ".aspx"') do del /s /q /f %a
chdir ..

Edit: would like a reason as to the downvotes so i could fix it. I find this question to be valid enough to not get penalized. shrug

4

1 回答 1

3

你可以这样做:

for /f "delims=ÿ" %a in ('dir /b /ad ^| find /v ".aspx"') do rd /s /q %a
for /f "delims=ÿ" %a in ('dir /b /a-d ^| find /v ".aspx"') do del /s /q /f %a

请先在测试目录上运行它。

另一种形式:

for /f "delims=ÿ" %a in ('dir /b /a-d') do if not "%~xa"==".aspx" del /q %a

作为批处理文件:

@echo off
for /f "delims=ÿ" %%a in ('dir /b /a-d ^| find /v ".aspx"') do del /s /q /f %%a

或者

@echo off
for /f "delims=ÿ" %%a in ('dir /b /a-d') do if not "%%~xa"==".aspx" del /q %%a

将其保存到文件中,如file.bat,或file.cmd然后运行x:\path\to\file.batx:\path\to\file.cmd.

于 2013-09-16T18:47:20.667 回答