This Vbs script will allow for you to browse for a directory folder and then it will send all of the file contents to an excel spreadsheet sorted alphabetically. This script can be used to gather and print a list of the music or video files you have in a particular location at home. At work or at the office it can be useful for listing the contents of a particular SMS inbox or simply to print a directory folders contents.
This script was originally intended as a lazy way for me to print a directory folders contents. In the past I use to issue a Dir command from the directory folder and pipe it out to a text file. Then I had to edit the file to remove all but the Filename. Finally I was able to print the text file for my records. In essence just think of it as an easy way to print a directory folders contents.
Note: This script will not enumerate any subfolders under the directory folder selected. That is a script for another day.
VBS Script:
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder (0, "Select The Folder To Enumerate :", (0))
If objFolder Is Nothing Then
Wscript.Quit
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "File Name"
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(objPath)
For each objFile in objFolder.Files
If objFolder.Files.Count > 0 Then
objExcel.Cells(intRow, 1).Value = objFile.Name
intRow = intRow + 1
Next
objExcel.Range("A1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
Set objRange = objExcel.Range("A1")
objRange.Sort objRange,1,,,,,,1
MsgBox "Done"
No Comments