elgin8949
(Elgin8949)
1
Description
I had a need to know all files in a folder and sub-folders but in an excel format. This script contains parts written by me and other people, but I no longer rememeber who.
The process will prompt for a directory to review. Upon selecting a directory, it will open excel and start to fill out the worksheet. During this time you will need to leave excel alone or the script will faulter.
There are tweaks needed on this, but the script will do what is needed.
Source Code
Set objDlg = WScript.CreateObject("Shell.Application")
Set objFile = objDlg.BrowseForFolder(&H0,"Select the Directory to Review",&H0001 + &H0010,"C:\")
objStartFolder = objfile.ParentFolder.ParseName(objfile.Title).Path
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "Folder"
objExcel.Cells(1, 2).Value = "File Name"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
objExcel.Cells(intRow, 1).Value = objfolder.Name
objExcel.Cells(intRow, 2).Value = objFile.Name
intRow = intRow + 1
Next
ShowSubfolders objFSO.GetFolder(objStartFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
objExcel.Cells(intRow, 1).Value = Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
objExcel.Cells(intRow, 2).Value = objFile.Name
intRow = intRow + 1
Next
ShowSubFolders Subfolder
Next
End Sub
objExcel.Range("A1:B1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
MsgBox "Process Complete"
Set objexcel = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set colFiles = Nothing
Set objStartFolder = Nothing
1 Spice up
elgin8949
(Elgin8949)
2
If needed to be in the background, set objexcel.visible = ‘False’ instead of positive.
pbedse
(Pradeep Bedse)
3
Elgin8949, Can we do make the index in html instead of Excel using this script. ?
elgin8949
(Elgin8949)
4
How would you need it in HTML, in just a simple table?
elgin8949
(Elgin8949)
5
I have created another version that outputs in HTML. It should do what you need, the script is here: http://community.spiceworks.com/scripts/show/1270-files-per-folder-html-output