windows 使用批处理文件或命令删除只读文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1564533/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:17:27  来源:igfitidea点击:

Deleting a read only file using batch file or command

windowsbatch-filecmddelete-file

提问by ckv

I would like to know a way of deleting a read only file using a batch file or a command.

我想知道一种使用批处理文件或命令删除只读文件的方法。

Suppose I have a DLL file named "abc.dll", and I am trying to delete this file using the following command in a batch file:

假设我有一个名为“abc.dll”的 DLL 文件,并且我试图在批处理文件中使用以下命令删除该文件:

del "C:\test\abcd.dll"

It does not allow me to do that and it throws access denied message. However if I change the read only attribute to non read only I am able to successfully delete it.

它不允许我这样做,它会抛出访问被拒绝的消息。但是,如果我将只读属性更改为非只读,我就可以成功删除它。

回答by Sebastiaan M

Specify /F, it will force deletion of read-only files. Also see

指定/F,它将强制删除只读文件。另见

del /?

However, that will not work when the file is in use.

但是,当文件正在使用时,这将不起作用。

回答by Daren Schwenke

del /fwill delete readonly files.

del /f将删除只读文件。