list folders and files using .vbs file

josianne

New member
Joined
Aug 14, 2014
Messages
5
Reaction score
0
Points
0
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:
[/COLOR]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
 
[COLOR=#333333]
 
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
 
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
 
thank you for the help bob phillips, but it still didnt separate each field on different columns :S
 
thank you snb!
it worked, but I still need to return the details of each file:
size - date created - last modified date
 
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.
 
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
 
[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]
 
hi bob phillips!
I make exactly that, but it returns 'parse error' - 'whitespace is not allowed at this location' at :


ObjOutFile.WriteLine(ObjFile.Path & ","
 
Back
Top