Results 1 to 10 of 10

Thread: list folders and files using .vbs file

  1. #1

    list folders and files using .vbs file



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hello guys!
    I'm very new on programming but I'm enjoying it so far .
    I need a tip to make a vbs file that returns a list of the subfolders and files of a main folder.
    SO FAR I HAVE THIS (but it doesnt separates the fields in different columns)
    Thank you so much for the help in advance!


    Code:
    Dim fso
    Dim ObjOutFile 
     
    Set fso = CreateObject("Scripting.FileSystemObject") 
     
    Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")
     
    ObjOutFile.WriteLine("File Path and Name ** " & "DateModified" & " ** Size in Kbs ** " & "Files on Folder")
     
    GetFiles("C:\Intel") 
     
    ObjOutFile.Close 
     WScript.Echo("Completed")
     Function GetFiles(FolderName) 
      
     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(ObjFile.Path & " ** " & ObjFile.DateLastModified & " ** " & ObjFile.Size) 
     Next       
      
     Set ObjSubFolders = ObjFolder.SubFolders 
     For Each ObjFolder In ObjSubFolders        
     ObjOutFile.WriteLine(ObjFolder.Path & " ** " & ObjFolder.DateLastModified & " ** " & ObjFolder.Size & " ** " & ObjFolder.Files.Count)    
     
                   
    GetFiles(ObjFolder.Path)  
     Next 
     End Function


  2. #2
    Code:
    Dim fsoDim ObjOutFile 
     
    Set fso = CreateObject("Scripting.FileSystemObject") 
     
    Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")
     
    ObjOutFile.WriteLine("File Path and NameDateModified,Size in Kbs,Files on Folder")
     
    GetFiles("C:\Intel") 
     
    ObjOutFile.Close 
     WScript.Echo("Completed")
     Function GetFiles(FolderName) 
      
     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(ObjFile.Path & "," & ObjFile.DateLastModified & "," & ObjFile.Size) 
     Next       
      
     Set ObjSubFolders = ObjFolder.SubFolders 
     For Each ObjFolder In ObjSubFolders        
     ObjOutFile.WriteLine(ObjFolder.Path & "," & ObjFolder.DateLastModified & "," & ObjFolder.Size & "," & ObjFolder.Files.Count)    
     
                   
    GetFiles(ObjFolder.Path)  
     Next 
     End Function

  3. #3
    Conjurer snb's Avatar
    Join Date
    May 2013
    Posts
    372
    Articles
    0
    Excel Version
    2020
    This suffices.

    Code:
    Sub M_snb()      
          createobject("Scripting.filesystemobject").createtextfile("C:\Overview.txt").write createobject("wscript.shell").exec("cmd /c Dir ""C:\Intel\*.*"" /s /b").stdout.readall
     End Sub

  4. #4
    thank you for the help bob phillips, but it still didnt separate each field on different columns :S

  5. #5
    thank you snb!
    it worked, but I still need to return the details of each file:
    size - date created - last modified date

  6. #6
    Quote Originally Posted by josianne View Post
    thank you for the help bob phillips, but it still didnt separate each field on different columns :S
    I put commas in, seeing as you were saving as a csv file, and if you import a csv file into Excel, guess what, separate columns.

  7. #7
    Conjurer snb's Avatar
    Join Date
    May 2013
    Posts
    372
    Articles
    0
    Excel Version
    2020
    Slightly adjusted:


    Code:
    Sub M_snb()
         createobject("Scripting.filesystemobject").createtextfile("C:\Overview.txt").write createobject("wscript.shell").exec("cmd /c Dir ""C:\Intel\*.*"" /s /a").stdout.readall 
    End Sub

  8. #8
    [Thank you snb!
    is there any form of displaying also the date of creation of the files?]


    Slightly adjusted:


    Code:
    Sub M_snb()
         createobject("Scripting.filesystemobject").createtextfile("C:\Overview.txt").write createobject("wscript.shell").exec("cmd /c Dir ""C:\Intel\*.*"" /s /a").stdout.readall 
    End Sub
    [/QUOTE]

  9. #9
    hi bob phillips!
    I make exactly that, but it returns 'parse error' - 'whitespace is not allowed at this location' at :


    ObjOutFile.WriteLine(ObjFile.Path & ","

  10. #10
    Conjurer snb's Avatar
    Join Date
    May 2013
    Posts
    372
    Articles
    0
    Excel Version
    2020
    You might have a look over here:

    http://www.snb-vba.eu/VBA_Bestanden_en.html#L_20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •