@echo off
REM turning off the output of commands to the screen
Set /P "%~1=Extension: "
if "%~1" == "" echo Extension not introduced
REM if you do not enter anything, the extension is not entered
if not exist "*.%~1" echo No files found
REM if you entered an extension that does not exist, it will give you no files found.
DEL /Q "*.%~1"
REM delete files with the specified extension without confirmation
我無法弄清楚“設定”是如何作業的。幫助做到這一點:啟動批處理后,您必須輸入擴展名,然后將其洗掉或輸出未找到。
uj5u.com熱心網友回復:
(不值得回答,但注釋不擅長顯示可讀代碼)
%~1是腳本的第一個引數。當我正確理解您時,您不需要任何引數,但您希望腳本要求輸入。
您必須使用變數 ( %variable%) 而不是引數:
@echo off
:label
set /p "ext=" & REM clear variable because `set /p` leaves it unchanged when you enter nothing
Set /P "ext=please enter Extension: "
if "%ext%" == "" echo Extension not introduced & goto :label
if not exist "*.%ext%" echo No files found & goto :label
DEL /Q "*.%ext%"
(洗掉了注釋并添加了一些基本的“代碼流”)
uj5u.com熱心網友回復:
為什么不嘗試通過使用If's、labels 和GoTo's 來簡化流程?
例子
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
For /F "Delims==" %%G In ('"(Set Ext) 2>NUL"') Do Set "%%G="
Set "Ext=%~1"
If Defined Ext GoTo ChkExt
:GetExt
ClS
Set /P "Ext=Enter extension [without leading period]>"
If ErrorLevel 1 GoTo GetExt
:ChkExt
Set Ext | %SystemRoot%\System32\find.exe "." 1>NUL
If Not ErrorLevel 1 GoTo GetExt
:DelExt
%SystemRoot%\System32\choice.exe /M "Delete all %Ext% files in
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/526348.html
標籤:批处理文件命令命令
下一篇:如何批量傳遞帶值的引數?
