Question : Convert what you see in a folder in Windows Explorer (Details View) into an Excel spreadsheet.

Is it possible to convert what you see in a folder in Windows Explorer (Details View) into an Excel spreadsheet?

Hence, the Excel spreadsheet will have a list of

- Filenames under Name column,
- dates under Date modified column
- file type  under type column
- file size under size column

I'm not sure which Zone this question belongs to. I hope this is the correct one.

Thanks!

Answer : Convert what you see in a folder in Windows Explorer (Details View) into an Excel spreadsheet.

try now.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
Const FOLDER_PATH = "c:\temp\files"
const OUTPUT_EXCEL_FILE = "c:\temp\output.xlsx"
const SHEET_HEADERS = "Name, Date Modified, Type, Size"
Const xlExcel7 = 51

On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = false
 
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Excel application not found."
    Wscript.Quit
End If
On Error GoTo 0

col=1
row=2

' Create a new workbook.
objExcel.Workbooks.Add

' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

for each header in Split(SHEET_HEADERS,",")
	objSheet.Cells(1, col).Value = header
	col=col+1
next

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(FOLDER_PATH)
For Each objFile in objFolder.Files
	objSheet.Cells(row, 1).Value = objFile.Name
	objSheet.Cells(row, 2).Value = objFile.DateLastModified
	objSheet.Cells(row, 3).Value = objFile.Type
	objSheet.Cells(row, 4).Value = objFile.Size & " KB"
	row=row+1
Next

objExcel.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs OUTPUT_EXCEL_FILE, xlExcel7
objExcel.ActiveWorkbook.Close false

' Quit Excel.
objExcel.Application.Quit

Set objSheet = Nothing
Set objExcel = Nothing

Wscript.Echo "done."
Random Solutions  
 
programming4us programming4us