windows 如何强制我的批处理文件隐藏 cmd 窗口并说“是”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19169567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I force my batch file to hide the cmd window and say "yes"?
提问by Radical924
Okay so I am trying to make a simple BAT file that deletes files in multiple folders. Now this is what I have so far. I would like it so it deletes all files and folders in the Temp directory but not folders in the data directory... I would also like it to say yes to the prompts. How do I do this???
好的,所以我正在尝试制作一个简单的 BAT 文件,该文件可以删除多个文件夹中的文件。现在这就是我到目前为止所拥有的。我希望它删除 Temp 目录中的所有文件和文件夹,但不删除数据目录中的文件夹......我还希望它对提示说是。我该怎么做呢???
@ECHO OFF
DEL "C:\ProgramData\TVersity\Media Server\data\*.*"
DEL "%LOCALAPPDATA%\Temp\*.*"
I am planning on adding in more directories into this BAT file so please if you can respond with "how to commands"... Because I would like to know how to specify whether to delete all folders and files or just files.
我计划在此 BAT 文件中添加更多目录,所以请您回复“如何执行命令”...因为我想知道如何指定是删除所有文件夹和文件还是仅删除文件。
Also how to automate the "yes" to all prompts.
还有如何自动对所有提示输入“是”。
回答by Joe Enos
del /s /q c:\somedirectory\*.*
should take care of deleting all files recursively without deleting the directories, in "quiet" mode, which doesn't give you the prompt.
应该注意递归删除所有文件而不删除目录,在“安静”模式下,它不会给你提示。
To delete an entire directory and all of its files and subdirectories, you can use rd
with the same flags:
要删除整个目录及其所有文件和子目录,您可以使用rd
相同的标志:
rd /s /q c:\somedirectory
回答by paddy
You can find out about the options available in the del
command by typing del /?
.
您可以del
通过键入来了解命令中可用的选项del /?
。
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
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.
/P Prompts for confirmation before deleting each file.
/F Force deleting of read-only files.
/S Delete specified files from all subdirectories.
/Q Quiet mode, do not ask if ok to delete on global wildcard
/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
In your case, you want
在你的情况下,你想要
DEL /Q "C:\ProgramData\TVersity\Media Server\data\*.*"
DEL /Q "%LOCALAPPDATA%\Temp\*.*"
回答by roblovelock
To exit your script you need to add "exit" at the end.
要退出您的脚本,您需要在最后添加“exit”。
To automatically press Y you can echo the character 'Y' and pipe it into your command.
要自动按 Y,您可以回显字符 'Y' 并将其通过管道传输到您的命令中。
For example:
例如:
@ECHO OFF
echo Y | DEL "C:\ProgramData\TVersity\Media Server\data\*.*"
echo Y | DEL "%LOCALAPPDATA%\Temp\*.*"
exit
回答by Endoro
回答by nephi12
start /min "" ".\batchfile.bat"
will start your batch file minimized from another batch file.
将启动从另一个批处理文件最小化的批处理文件。