有人可以帮助我创建一个批处理文件,指出它在命令行中删除的内容吗?如何为del命令创建一个批处理文件,但是详细
我是批量初学者,并没有这样做过。
我知道没有/V
命令del
所以我认为这批可能是我的答案。
有人可以帮忙吗?
有人可以帮助我创建一个批处理文件,指出它在命令行中删除的内容吗?如何为del命令创建一个批处理文件,但是详细
我是批量初学者,并没有这样做过。
我知道没有/V
命令del
所以我认为这批可能是我的答案。
有人可以帮忙吗?
写文件下的test.bat:
set delFileList=%*
FOR %%A IN (%delFileList%) DO (
DEL %%A
echo file %%A deleted
)
警告 -该解决方案确实不确认提示,如果用户试图删除整个目录。请注意!
下面是LISTDEL.BAT,它支持大多数正常的DEL选项。
我相信LISTDEL.BAT非常强大。我能想到的唯一限制是,如果共享相同%TEMP%文件夹的两个进程尝试在几乎同一时间运行实用程序,它可能会失败。代码被广泛记录在案。
:::
:::LISTDEL.BAT [/?] [/F] [/S] [/A[[:]attributes]] Names
:::
::: Deletes one or more files in much the same way as DEL, except each
::: deleted file is listed.
:::
::: Unlike DEL, LISTDEL never prompts for confirmation of global wildcard.
::: Also, the /P option is not supported.
:::
::: names Specifies a list of one or more files or directories.
::: Wildcards may be used to delete multiple files. If a
::: directory is specified, all files within the directory
::: will be deleted.
:::
::: /? Display this help information
:::
::: /F Force deleting of read-only files.
:::
::: /S Delete specified files from all subdirectories.
:::
::: /A Selects files to delete based on attributes
::: attributes R Read-only files S System files
::: H Hidden files A Files ready for archiving
::: I Not content indexed Files L Reparse Points
::: - Prefix meaning not
:::
::: LISTDEL.BAT was written by Dave Benham and originally posted at:
::: http://stackoverflow.com/a/26680846/1012053
:::
@echo off
setlocal disableDelayedExpansion
:: Print help if /? used
echo(%*|findstr /ir "\</\?\>" >nul && (
for /f "delims=: tokens=*" %%A in ('findstr /b ":::" "%~f0"') do echo(%%A
exit /b 0
)
:: Fail if /P option used
echo(%*|findstr /ir "\</P\>" >nul && (
echo Invalid switch - "P".>&2
exit /b 0
)
:: Determine if /F option was used and save value
echo(%*|findstr /ir "\</F\>" >nul && set "force=/f" || set "force="
:: Determine length of the delete prompt that varies by language.
:: The English prompt is ", Delete (Y/N)? ", which results in -16.
set "tempFile=%temp%\showDel.tmp"
for %%F in ("%tempfile%") do >"%tempFile%" echo %%~fF
del /p "%tempFile%" <nul >"%tempFile%2"
for %%A in ("%tempFile%") do for %%B in ("%tempFile%2") do set /a "promptLen=%%~zA-%%~zB"
del "%tempFile%" "%tempFile%2"
:: Iterate list of files to be deleted via DEL /P /Q plus user supplied arguments.
:: No files are deleted because stdin is disabled - only a listing is produced.
:: Each listed file contains an unwanted delete prompt at the end.
for /f "delims=" %%F in ('del /p /q %* ^<nul') do (
%= Get the full path to the file by stripping off the trailing delete prompt =%
%= Toggle delayed expansion on and off to protect ! that may be in the path =%
set "file=%%F"
setlocal enableDelayedExpansion
set "file=!file:~0,%promptLen%!"
%= Attempt to delete the file and pipe any error message to FINDSTR. =%
%= Redirect FINDSTR output (any found error message) back to stderr. =%
%= If error message found, then inform what file coudn't be deleted, =%
%= else list the deleted file. =%
%= File attribute restrictions have already been applied in outer loop, =%
%= so DEL /A option is used to disregard file attributes. =%
del %force% /a "!file!" 2>&1 >nul | findstr . >&2 && >&2 echo Unable to delete !file!||echo !file!
endlocal
)
exit /b 0
编辑 - 添加帮助设施,并解除/ P选项。 – dbenham 2014-10-31 19:11:16
这是一个很好的第一次尝试,但如果它试图删除一个只读文件,它不会表现良好。另外,如果它支持许多标准的DEL选项,它将会很好。 – dbenham 2014-10-31 18:05:50