2017-01-22 30 views
0

我想在當前目錄的所有子文件夾中運行一個vbscript。 到目前爲止,我有:使用vbscript在所有子文件夾中運行另一個vbscript?

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

但是,這並不工作。如果我刪除了*\它將在當前的目錄中運行,但不是潛艇。我知道我錯過了一些簡單的事情。一直在尋找和嘗試幾個小時都無濟於事。

+1

搜索「VBScript中的子文件夾遞歸網站:stackoverflow.com」 –

+0

嗯...... *「一直在尋找和嘗試新事物了幾個小時也沒有用」 *真的,我在4分鐘前搜索並發現重複,你搜索了什麼? – Lankymart

回答

0

從你的代碼庫中找到了你,並根據你的需求進行調整。 未經測試,我在過去的幾年裏更加喜歡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 

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

+0

當你決定回答這樣的問題時,你只需要鼓勵更多。這個問題最多也就是窮人,並且很少或根本沒有嘗試自己來解決這個問題,更不用說它也被回答過了。 – Lankymart

+0

是的,但你嚇跑新用戶那樣,沒有看到它是一個雙重 – peter

+0

NB:他們要求的是一個VBScript解決方案,而不是Ruby。 – Lankymart