VBS脚本把一个目录下所有文件路径写到txt

2025年05月05日 13:00
有1个网友回答
网友(1):

Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Dim fld
path=fso.GetParentFolderName(WScript.ScriptFullName)
path="d:\test\" '注释掉这句,列出脚本所在目录
If fso.FolderExists(path) Then
    Set fld=fso.GetFolder(path)
    Dim fl
    Dim Text
    For Each fl In fld.Files
        Text = Text & fso.BuildPath(fl.Path,fl.Name) & vbCrLf
    Next
    Dim st
    Set st=fld.CreateTextFile("dirList.txt")
    st.Write Text
    st.Close
End If