将所有以句点开头的 RO 文件更改为 RW
我需要在目录结构中搜索以句点开头的所有文件(不要问...)并将它们从只读更改为读写。我可以使用第一个命令识别这些文件,但如何将其转换为第二个命令?
dir .*.* /s /a-D /ar
现在我想获取该输出并运行 attrib +r。这就是我得到的,但它不起作用。
for /f %f in ('dir .*.* /s /a-D /ar') DO "ATTRIB +R" "%G"
我想我已经很接近了,但是 DOS 批处理命令从来没有像我期望的那样工作(我的问题,不是 DOS 的问题)
I need to search a directory structure for all files beginning with a period (don't ask...) and change them from read-only to rw. I can identify those files with the first command, but how can I translate that into the 2nd command?
dir .*.* /s /a-D /ar
Now I want to take that output and run attrib +r. This is what I've gotten, but it isn't working.
for /f %f in ('dir .*.* /s /a-D /ar') DO "ATTRIB +R" "%G"
I think I am close, but DOS batch commands have never worked as I expect them to (my problem, not DOS's)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用的原因是
attrib +r
使处理后的令牌再次变为只读,而且还因为您在应该使用小写字母的地方使用了大写 %G。在 Windows 中,只读文件与 Linux 不同,您可以将文件标记为只读或不标记。
如果它不是只读的,它将使用文件夹/文件的 ACL 中找到的属性。
通常它会生成 RW 文件而不是只读文件。
您可以在这里阅读更多相关信息:
http://msdn.microsoft.com/en -us/magazine/cc982153.aspx
因此,对于你的问题:(
因为我没有任何以 为前缀的文件或文件夹。我无法测试并查看上述内容是否有效,你可能想使用 %f 代替%g,具体取决于您要使用的令牌。)
上面的代码将执行
attrib -r
操作,从而删除只读属性。您可能希望对要作为 .bat、.cmd 等执行的批处理脚本使用双 %%。
如
for /?
帮助屏幕中所述:此外:
The reason it's not working is because
attrib +r
makes the processed tokens read-only again and also because you use capital %G where you should use small letters.In Windows read-only files are different from Linux in ways that you either mark a file as read-only or not.
If it is not read-only it will use the properties found in the ACL for the folder/file.
Typically it will generate the file RW instead of Read-Only.
You can read more about it here:
http://msdn.microsoft.com/en-us/magazine/cc982153.aspx
So for your question:
(As I dont have any files or folders prefixed with . I cannot test and see if the above works, you may want to use %f instead of %g, depending on which token you want to use.)
The above will do
attrib -r
which removes the read-only attribute.You may want to use double %% for batch-scripts that are to be executed as .bat, .cmd etc.
As stated in the
for /?
help screen:Further more: