VBS获取文件夹下所有文件名并写入TXT文件

    技术2025-12-23  15

    Option Explicit Const File_NAME = "E:\List.txt" Const HOME_PATH = "C:\html" Dim myList Set myList = CreateObject("System.Collections.ArrayList") Dim fso Set fso = CreateObject("Scripting.FileSystemObject") If (fso.fileexists(File_NAME)) Then fso.DeleteFile File_NAME End If getAllFolderAndFiles HOME_PATH & "\video" WriteText myList Function WriteText(myList) Dim i With CreateObject("ADODB.Stream") .Type = 2 .Charset = "UTF-8" .Open For i = 0 To myList.Count - 1 .WriteText myList.Item(i) .WriteText vbCrLf Next .SaveToFile File_NAME, 2 .Flush .Close End With End Function Function getAllFolderAndFiles(strPath) Dim f, fso Set fso = CreateObject("Scripting.FileSystemObject") For Each f In fso.GetFolder(strPath).Files myList.add Replace(Replace(f.path, HOME_PATH, ""), "\", "/") Next For Each f In fso.GetFolder(strPath).SubFolders getAllFolderAndFiles f.Path Next End Function
    Processed: 0.019, SQL: 9