Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 686

How to print the recursively parsed data into a .csv or .xls file using VBscript

$
0
0
Hi, i am new to VB scripting and developing a small script, which recursively parses the folders/sub-folders in a given path for the files with file extension _George.doc or _Peter.docx and it has to list down all the data into a csv file showing the path of the file and also the name of the file. can some one please help me in this regard.there is some error in the below code which i am unable to trace it.

Dim fso
Dim ObjOutFile

'Creating File System Object
Set fso = CreateObject("Scripting.FileSystemObject")

'Create an output file
Set ObjOutFile = fso.CreateTextFile("List_of_Missing_Rack_Records.csv")

'Writing CSV headers
ObjOutFile.WriteLine("Parent_Folder_Name,")

'Call the GetFile function to get all files
GetFiles("T:\CNS_DATA\Parent")

'Close the output file
ObjOutFile.Close

WScript.Echo("Completed")

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

'Write all files to output files
For Each ObjFile In ObjFiles
ObjOutFile.WriteLine("File," & ObjFile.Name & "," & ObjFile.Path)
If (InStr(objFile.Name, ".") > 0) Then
'If the file's extension is "doc", write the path to the output file.
If (LCase(Mid(objFile.Name, InStrRev(objFile.Name, "."))) = ".docx") AND (LCase(Mid(objFile.Name, InStrRev(objFile.Name, "."))) = ".doc") Then _
objTS.WriteLine(objfile.Path)
End If
Next
Wscript.Echo
ShowSubfolders objFSO.GetFolder(objStartFolder)


End Function

Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub

Viewing all articles
Browse latest Browse all 686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>