需要从vbs脚本输出帮助

时间:2014-09-29 03:36:28

标签: vbscript directory subdirectory

我发现这个脚本说它可以列出文件夹的子文件夹。如何更改此选项以便列出文件夹并将其保存到文本文件中?

我用它来列出文本文件中用户保存的地图。

以下是代码:

Sub ShowFolderList(folderspec)
    Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(folderspec)
    Set fc = f.SubFolders
    For Each f1 in fc
        s = s & f1.name 
        s = s &  vbCrLf
    Next
    MsgBox s
End Sub

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

只有几行:

Sub ShowFolderList(folderspec)
    Dim fs, f, f1, fc, s, logfile
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set logfile = fs.OpenTextFile("C:\temp\logfile.txt", 8, True) ' Open a log file for appending
    Set f = fs.GetFolder(folderspec)
    Set fc = f.SubFolders
    For Each f1 in fc
        s = s & f1.name 
        s = s &  vbCrLf
    Next
    logfile.Write s ' Write content of s to log file
    MsgBox s
End Sub