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."
|