【问题标题】:using a vbscript to run another vbscript in all subfolders? [duplicate]使用 vbscript 在所有子文件夹中运行另一个 vbscript? [复制]
【发布时间】:2017-06-07 00:38:42
【问题描述】:

我正在尝试在当前目录的所有子文件夹中运行 vbscript。 到目前为止,我有:

CreateObject("Wscript.Shell").Run("""*\dirlistnew.vbs""")

但这不起作用。如果我删除 *\ 它将在当前目录中工作,但不是潜艇。我知道我错过了一些简单的东西。搜索和尝试了几个小时都无济于事。

【问题讨论】:

  • 搜索“vbscript 子文件夹递归站点:stackoverflow.com”
  • 嗯... “一直在搜索和尝试几个小时都无济于事。” 真的,我在 4 分钟前搜索并找到了重复项,你搜索了什么?

标签: vbscript


【解决方案1】:

从我的 sn-ps 库中得到这个,根据你的需要进行调整。 未经测试,过去几年我更喜欢 Ruby。

'call our sub with the desired path as option
' this needs to be a Folder object, not a String
' FSO.GetFolder will return that object given a path as string
ShowSubfolders FSO.GetFolder(path)

Sub CreateHtml(path)
  ' put here the code from your other script (best)
  ' or do your call to execute the other script
  ' you probably need the path so you pass it as a parameter
End Sub

Sub ShowSubFolders(Folder)
' a Folder has the method SubFolders, 
' gives a collection of subfolders that can be enumerated
' with For Each construct
  For Each Subfolder in Folder.SubFolders
    ' print the subfolder so you can follow the progress
    Wscript.Echo Subfolder.Path
    ' and call the sub that creates the html file
    CreateHtml Subfolder.Path
    ' here the magic of recursion, the sub is calling itself with 
    ' as parameter the subfolder to process the subsubfolders etc
    ShowSubFolders Subfolder
  Next
End Sub

注意,在 Ruby 中它只是一行 Dir["#{folder}/*"].each{|f| puts f if File.directory?(f) }

【讨论】:

  • 当你决定回答这样的问题时,你只会鼓励更多的问题。这个问题充其量是很糟糕的,并且很少或根本没有尝试自己解决问题,更不用说以前也有人回答过。
  • 是的,但你这样吓跑了新用户,虽然没有看到它是双重的
  • 注意:他们要求的是 VBScript 解决方案,而不是 Ruby。
  • 如果他们那么容易被吓跑,那么这里不适合他们。我犯了同样的错误,但我没有逃跑,而是阅读了旅行并检查了How to Ask,我在Meta Stack Overflow上询问并进行了调整。我们不应该改变,因为有些人太敏感而无法重新调整并意识到我们正在努力帮助他们。所有这一切都是为了验证他们所做的事情是正确的,这是错误的信息。
  • 我想他现在明白了......所以让我们结束这个讨论
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多