隐藏桌面图标的批处理脚本
我正在尝试制作一个隐藏桌面上一些图标的脚本。当我在命令提示符中逐行运行它时,它可以工作,但是当我在 cmd 中运行 *.bat 文件时,它显示“此时属性是意外的”。 这是代码:
set address=file.ext
set attributes=attrib %address%
for /F "tokens=*" %i in ("%attributes%") do set var=%i
set var=%var: =%
if %var:~1,1%==H (attrib -H %address%)else (attrib +H %address%)
I'm trying to make a script that hides some icons on desktop. When I run it line by line in command promt it works, but when I run the *.bat file in cmd it says "attributesi was unexpected at this time."
Here is the code:
set address=file.ext
set attributes=attrib %address%
for /F "tokens=*" %i in ("%attributes%") do set var=%i
set var=%var: =%
if %var:~1,1%==H (attrib -H %address%)else (attrib +H %address%)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
在批处理文件中运行时,for 循环变量需要 %% 而不是 %。但从命令行来看,% 工作得很好。
如果您需要有关批处理文件的任何其他帮助,您应该查看 Rob van der Woude 有关批处理文件脚本的页面。这是一种非常丰富的语言资源,但目前越来越难找到相关信息。
说到这里,我不得不提到 Powershell 脚本已经在很大程度上取代了 DOS 批处理文件脚本(并且有充分的理由)。几乎任何可以在 DOS 批处理文件中执行的操作,现在都可以在 Powershell 脚本中更轻松地完成。如果您计划进行更多基于 Windows 的脚本编写,绝对值得一试。
Try this:
The for loop variables need %% instead of % when run in a batch file. But from the command line, % works just fine.
If you need any additional help with batch files, you should check out Rob van der Woude's pages on batch file scripting. It's a very rich resource on a language that's becoming increasingly difficult to find information on.
Speaking of which, I feel compelled to mention that Powershell scripting has largely replaced DOS batch file scripting (and for good reason). Almost anything you can do in a DOS batch file, you can now do easier in a Powershell script. Definitely worth checking into if you plan on doing more Windows-based scripting.
Hidedesktopicons.exe
没有为我做任何事情,但给出的链接实际上有效。 http://www.actualtools.com/forum/read.php ?FID=8&TID=1072Hidedesktopicons.exe
wasn't doing anything for me, but link that is given actually works. http://www.actualtools.com/forum/read.php?FID=8&TID=1072