小弟近来在学习批处理, 想利用批处理中的for语句, 查询某一文件夹下所有子文件夹,并为每个子文件夹在相同目录下建立一个快捷方式(由于觉得用dos命令建快捷方式不太好弄,于是选用vbs),代码如下:
@echo off
for /f %%d in ('dir /a:d/s/b') do (
echo Dim WshShell,Shortcut >>tmp.vbs
echo Dim path,fso >>tmp.vbs
echo path="%%d" >>tmp.vbs
echo Set fso=CreateObject("Scripting.FileSystemObject") >>tmp.vbs
echo Set WshShell=WScript.CreateObject("WScript.Shell") >>tmp.vbs
echo Set Shortcut=WshShell.CreateShortCut(%%d.lnk) >>tmp.vbs
echo Shortcut.TargetPath=path >>tmp.vbs
echo Shortcut.Save >>tmp.vbs
"%SystemRoot%\System32\WScript.exe" tmp.vbs
@del /f /s /q tmp.vbs
)
但是在运行中出现如下报错信息;
1) dos窗口中报错: 另一个程序正在使用此文件,进程无法访问。
2)vbs窗口弹出报错,打开tmp.vbs文件,内容如下:
Set fso=CreateObject("Scripting.FileSystemObject" '此处没有")",而原文件中有")"
Set fso=CreateObject("Scripting.FileSystemObject"
Set fso=CreateObject("Scripting.FileSystemObject"
Set fso=CreateObject("Scripting.FileSystemObject"
Set fso=CreateObject("Scripting.FileSystemObject"
Set fso=CreateObject("Scripting.FileSystemObject"
Set WshShell=WScript.CreateObject("WScript.Shell")
Set Shortcut=WshShell.CreateShortCut(%d.lnk)
Shortcut.TargetPath=path
Shortcut.Save