多个文件的批处理文件和 CHOICE 命令

发布于 2025-01-09 17:58:53 字数 677 浏览 0 评论 0原文

有一个 Windows 程序也可以从上下文菜单中擦除文件和文件夹,即使根本没有确认,然后我创建了一个包含以下内容的批处理文件

@ECHO OFF
CHOICE /M "Do you want to Wipe Files"
IF ERRORLEVEL 2 GOTO QUIT
IF ERRORLEVEL 1 GOTO RUN
:RUN
START "" "C:\Program Files\MyProgram\myexec.exe" /wipe "%~1"
EXIT
:QUIT
EXIT

和一个包含以下条目的注册表项,

[HKEY_CLASSES_ROOT\*\shell\wipefiles\command]
@="\"C:\\Program Files\\MyProgram\\myexec-start.cmd\" \"%1\""

只是为了在擦除文件之前获得安全机会或文件夹,它确实有效。

但是,如果选择了多个文件,那么它会提示您根据文件数量多次回答 YN,并且 cmd 窗口保持打开状态,直到您点击所选文件数量的 YN 次。

有没有办法无论选定的文件有多少,都可以回答一次 YN (关闭 cmd 屏幕)?

Having a Windows program that does wipe files and folders from the context menu too even with no confirmation at all then I created a batch file with the following content

@ECHO OFF
CHOICE /M "Do you want to Wipe Files"
IF ERRORLEVEL 2 GOTO QUIT
IF ERRORLEVEL 1 GOTO RUN
:RUN
START "" "C:\Program Files\MyProgram\myexec.exe" /wipe "%~1"
EXIT
:QUIT
EXIT

and a registry key with the following entry

[HKEY_CLASSES_ROOT\*\shell\wipefiles\command]
@="\"C:\\Program Files\\MyProgram\\myexec-start.cmd\" \"%1\""

just to get a safety chance before to wipe the file or the folder and it does work.

However if multiple files are selected then it prompts you to answer Y or N for the times as far as the number of files is and furthermore the cmd window remains open until you hit Y or N the times as far as the number of selected files is.

Is there a way in order to answer a single time Y or N (closing the cmd screen) regardless of the number of selected files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世蒼涼 2025-01-16 17:58:53

似乎没有简单的方法可以执行您从上下文菜单中请求的操作,因为会为每个选定的文件打开一个单独的进程。
但可以通过“发送到”菜单轻松完成:
在 SendTo 文件夹中为脚本创建快捷方式,现在您可以发送任意数量的文件或文件夹。
脚本内容如下:

@ECHO OFF
CHOICE / M "Do you want to Wipe Files"
IF ERRORLEVEL 2 GOTO QUIT

:: If your software enables file processing in a chain, such as myexec.exe /wipe filename1 filename2 ..., use this syntax:
START "" "C:\Program Files\MyProgram\myexec.exe" /wipe %*
:: If not, use the for loop:
for %%f in (%*) do START "" "C:\Program Files\MyProgram\myexec.exe" /wipe %%f

: QUIT

也许这与主题有点偏离,但您可以在 VBScript 中执行此操作,如下所示:

Set Shell = CreateObject("WScript.Shell")
if MsgBox("Do you want to Wipe Files?", vbQuestion + vbYesNo, "wipefiles") = vbYes then
  for each Arg in WScript.Arguments
    Shell.Run """C:\Program Files\MyProgram\myexec.exe"" /wipe " & """" & Arg & """",0,True
  Next
end if

它将显示一个图形消息框,要求用户确认删除,而无需任何终端窗口。

There seems to be no simple way to do what you request from the context menu, since a separate process is opened for each selected file.
But it can be done easily from the send to menu:
Create a shortcut in the SendTo folder for your script, and now you can send as many files or folders as you want.
The script reads as follows:

@ECHO OFF
CHOICE / M "Do you want to Wipe Files"
IF ERRORLEVEL 2 GOTO QUIT

:: If your software enables file processing in a chain, such as myexec.exe /wipe filename1 filename2 ..., use this syntax:
START "" "C:\Program Files\MyProgram\myexec.exe" /wipe %*
:: If not, use the for loop:
for %%f in (%*) do START "" "C:\Program Files\MyProgram\myexec.exe" /wipe %%f

: QUIT

Maybe it's a bit of a deviation from the theme, but you can do it in VBScript like this:

Set Shell = CreateObject("WScript.Shell")
if MsgBox("Do you want to Wipe Files?", vbQuestion + vbYesNo, "wipefiles") = vbYes then
  for each Arg in WScript.Arguments
    Shell.Run """C:\Program Files\MyProgram\myexec.exe"" /wipe " & """" & Arg & """",0,True
  Next
end if

It will display a graphical message box asking the user to confirm the deletion, without any terminal window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文