Re: owner propety on files





"John W" wrote:


"JayJ" <JayJ@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:0AB23A8B-B018-4AD3-8E21-633DAEF387CA@xxxxxxxxxxxxxxxx
I have a script that works. I am sure there is a better way to do it.

I am outputing the file properties for all files in a specified directory to
an excel file. I can not figure out a way to include the owner property. I
found something that does pull owner information - it also pulls alot of
information i don't want and i have no idea how to integrate it into my
existing script.

Below i pasted both the script that pulls owner property and my existing
script. Any help getting getting the "existing script" to pull the ower
property is appreciated.

***********************
' pulls info on owners and extras

Dim arrHeaders(34)

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Scripts")

For i = 0 to 33
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next

For Each strFileName in objFolder.Items
For i = 0 to 33
Wscript.Echo i & vbtab & arrHeaders(i) _
& ": " & objFolder.GetDetailsOf(strFileName, i)
Next
Next

***************************
'Existing script

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='H:\scripts'} Where " _
& "ResultClass = CIM_DataFile")
i = 2
Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
'open spreadsheet
Set objWorkbook = objExcel.Workbooks.Open("h:\spreadsheet.xls")
Set objWorksheet = objWorkbook.Worksheets(1)
objExcel.Cells(1, 1).Value = "File Name"
objExcel.Cells(1, 2).Value = "File Path"
objExcel.Cells(1, 3).Value = "File Size in Bytes"
objExcel.Cells(1, 4).Value = "Date Created"
objExcel.Cells(1, 5).Value = "Last Accessed"
objExcel.Cells(1, 6).Value = "Last Modified"

objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 2).Font.Bold = TRUE
objExcel.Cells(1, 3).Font.Bold = TRUE
objExcel.Cells(1, 4).Font.Bold = TRUE
objExcel.Cells(1, 5).Font.Bold = TRUE
objExcel.Cells(1, 6).Font.Bold = TRUE

For Each objItem In colFileList

objworksheet.cells(i, 1).Value = objItem.FileName
objWorksheet.cells(i, 2).value = objItem.Description
objWorksheet.cells(i, 3).value = objItem.FileSize
objWorksheet.cells(i, 4).value = WMIDateStringToDate(objItem.CreationDate)
objWorksheet.cells(i, 5).value = WMIDateStringToDate(objItem.LastAccessed)
objWorksheet.cells(i, 6).value = WMIDateStringToDate(objItem.LastModified)


i = i + 1


Next

Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
WMIDateStringToDate = CDate(Mid(dtmDate,5,2) & "/" & _
Mid(dtmDate,7,2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate,9,2) & ":" & Mid(dtmDate,11,2) & ":" &
Mid(dtmDate,13,2))
End Function


Dim arrHeaders(34)

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("H:\DoubleTake\scripts")

For j = 0 to 33
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, j)
Next

For Each strFileName in objFolder.Items
For j = 0 to 33
Wscript.Echo i & vbtab & arrHeaders(j) _
& ": " & objFolder.GetDetailsOf(strFileName, j)
Next
Next




You can use FileSystemObject to get most file properties; you don't need to use WMI or mess around with date formatting. Try
this, which does everything you asked for:

Option Explicit

Const cOwner = 8

Dim sFolder
Dim i, sHeadings
Dim objExcel, objWorkbook, objWorksheet
Dim objFso, objFolder, objFiles, objFile
Dim objShell, objShFolder, objItem

sFolder = "C:\temp"

sHeadings = Array("File Name", "File Path", "File Size in Bytes" ,_
"Date Created", "Last Accessed", "Last Modified", "Owner")

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open("c:\temp\spreadsheet.xls")
Set objWorksheet = objWorkbook.Worksheets(1)

With objWorksheet
For i = 0 To UBound(sHeadings)
.Cells(1,i+1).Value = sHeadings(i)
Next
.Range(.Cells(1,1), .Cells(1,i)).Font.Bold = True
End With

'Get properties of files in folder

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(sFolder)
Set objFiles = objFolder.Files

Set objShell = CreateObject("Shell.Application")
Set objShFolder = objShell.Namespace(sFolder)

i = 2
For Each objFile In objFiles
Set objItem = objShFolder.ParseName(objFile.Name)

With objWorksheet
.Cells(i,1).Value = objFile.Name
.Cells(i,2).Value = objFile.Path
.Cells(i,3).Value = objFile.Size
.Cells(i,4).Value = objFile.DateCreated
.Cells(i,5).Value = objFile.DateLastAccessed
.Cells(i,6).Value = objFile.DateLastModified
.Cells(i,7).Value = objShFolder.GetDetailsOf(objItem, cOwner)
End With
i = i + 1
Next

This works great. Thank you! I will need to research the shell.application. I really don't know much about how to use it.

I did find one issue. Not sure if it is something with a version I have or
not. I had to change the Cowner constant to 12. This returns the owner. 8
returned size in kb. I found a list of constants online and it also shows
that 8 should be correct so i don't know...

Another question if you don't mind. Can i take this script and easily make
it recurse through subfolders and output the same information in the same
way? The path would show the hierarchy..
.



Relevant Pages

  • Re: owner propety on files
    ... I'm guessing the script would fire on ... Dim i, sHeadings ... Dim objExcel, objWorkbook, objWorksheet ... Dim objFolder, objFiles, objFile, objSubFolder ...
    (microsoft.public.scripting.vbscript)
  • Re: owner propety on files
    ... Below i pasted both the script that pulls owner property and my existing ... Dim arrHeaders ... Dim objExcel, objWorkbook, objWorksheet ... Dim objFso, objFolder, objFiles, objFile ...
    (microsoft.public.scripting.vbscript)
  • Re: owner propety on files
    ... I find also show the constant as 8 for owner. ... Dim i, sHeadings ... Dim objExcel, objWorkbook, objWorksheet ... Dim objFolder, objFiles, objFile, objSubFolder ...
    (microsoft.public.scripting.vbscript)
  • Re: Find all access database
    ... I don't to reinvent the wheel and start a script from scratch so ... ' steps recursively through folder and outputs all files, ... Dim i, sHeadings ... Dim objExcel, objWorkbook, objWorksheet ...
    (microsoft.public.scripting.vbscript)
  • Re: owner propety on files
    ... I had to change the Cowner constant to 12. ... Dim i, sHeadings ... Dim objExcel, objWorkbook, objWorksheet ... Dim objFolder, objFiles, objFile, objSubFolder ...
    (microsoft.public.scripting.vbscript)