列出文件夹和子文件夹中的所有文件而不延长

时间:2016-11-29 19:35:17

标签: vbscript

我遇到过以下我非常喜欢使用的脚本,但我希望不要将.extention放在最后

Dim fso
Dim ObjOutFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set ObjOutFile = fso.CreateTextFile("C:\Users\User\Movies.csv")

ObjOutFile.WriteLine("Type,File Name,Size")

GetFiles("E:\")

ObjOutFile.Close

Function GetFiles(FolderName)
    On Error Resume Next

    Dim ObjFolder
    Dim ObjSubFolders
    Dim ObjSubFolder
    Dim ObjFiles
    Dim ObjFile

    Set ObjFolder = fso.GetFolder(FolderName)
    Set ObjFiles = objfolder.Files

    For Each ObjFile In ObjFiles
    ObjOutFile.WriteLine("File," & ObjFile.Name & "," & objFile.Size & "," & objFile.Type)
    Next

    Set ObjSubFolders = ObjFolder.SubFolders

    For Each ObjFolder In ObjSubFolders

        ObjOutFile.WriteLine("Folder," & ObjFolder.Name)


        GetFiles(ObjFolder.Path)
    Next

End Function

我这是垃圾,但我真的会帮忙

1 个答案:

答案 0 :(得分:1)

使用FileSystemObject的.GetBaseName()方法。如:

>> WScript.Echo goFS.GetBaseName("c:\dir\name.ext")
>>
name