Board logo

标题: VBS循环产生的参数怎么传递 [打印本页]

作者: yywd    时间: 2008-6-3 15:30     标题: VBS循环产生的参数怎么传递

vbs循环产生的参数怎么传递

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\1\0.txt", 1)
set WshShell = WScript.CreateObject("WScript.Shell")  
Set objFSO = CreateObject("Scripting.FileSystemObject")  
strFolder = "d:\1\"   
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
filename = strLine  
Set objFile = objFSO.GetFile(filename)
set oShellLink = WshShell.CreateShortcut(strFolder & objFSO.GetBaseName(filename) & ".lnk")  
oShellLink.TargetPath = objFile  
oShellLink.WindowStyle = 1  
oShellLink.WorkingDirectory = objFSO.GetParentFolderName(filename)  
oShellLink.Save
Loop
objFile.Close

这个只传递一次就完了
作者: breakan    时间: 2008-8-10 21:47

能说清楚点儿么?你要干什么?
作者: huahua0919    时间: 2008-8-17 11:44

Do while objFile.AtEndOfStream <> true
作者: zqz0012005    时间: 2008-9-20 17:51

Set objFile = objFSO.GetFile(filename)
这一句有问题,对象实例重名,会将开始的Set objFile = objFSO.OpenTextFile("d:\1\0.txt", 1)替换,导致第2次循环时objFile.AtEndOfStream出现错误

而且这一句似乎没有必要(不知道你的代码是不是只有这么多)

要创建很多个快捷方式,最好使用过程
  1. Set objFSO = CreateObject("Scripting.FileSystemObject")
  2. Set objFile = objFSO.OpenTextFile("d:\1\0.txt", 1)
  3. set WshShell = WScript.CreateObject("WScript.Shell")  
  4. strFolder = "d:\1\"   
  5. Do Until objFile.AtEndOfStream
  6. makelink RePlace(objFile.ReadLine,"""","")
  7. Loop
  8. objFile.Close
  9. Sub makelink(filename)
  10. Set f = objFSO.GetFile(filename)   '似乎没有必要
  11. set oShellLink = WshShell.CreateShortcut(strFolder & objFSO.GetBaseName(filename) & ".lnk")  
  12. oShellLink.TargetPath = f          '此处直接用filename即可
  13. oShellLink.WindowStyle = 1  
  14. oShellLink.WorkingDirectory = objFSO.GetParentFolderName(filename)  
  15. oShellLink.Save
  16. End Sub
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2