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

Re: owner propety on files by John

John
Wed Sep 05 12:12:21 PDT 2007


"JayJ" <JayJ@discussions.microsoft.com> wrote in message news:0AB23A8B-B018-4AD3-8E21-633DAEF387CA@microsoft.com...
>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



Re: owner propety on files by JayJ

JayJ
Wed Sep 05 14:42:02 PDT 2007



"John W" wrote:

>
> "JayJ" <JayJ@discussions.microsoft.com> wrote in message news:0AB23A8B-B018-4AD3-8E21-633DAEF387CA@microsoft.com...
> >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..

Re: owner propety on files by John

John
Thu Sep 06 03:41:32 PDT 2007


"JayJ" <JayJ@discussions.microsoft.com> wrote in message news:50EB74C4-870B-41C2-8977-0482ED27281E@microsoft.com...
>
>> 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...

Which OS are you using? Both the references I found say it's 8 for Windows 2000, XP and 2003:

http://classicasp.aspfaq.com/files/directories-fso/how-do-i-find-the-owner-author-and-other-properties-of-a-file.html

http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_lunl.mspx?mfr=true

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

Sure. Put the file processing in a subroutine and call it recursively for each subfolder. A quick Google shows the technique:

http://groups.google.co.uk/group/microsoft.public.scripting.vbscript/browse_frm/thread/ae0662d14038c45b/f3ad5006efe5fb5b?lnk=gst&q=recursive+folders&rnum=2#f3ad5006efe5fb5b

Here's my modified script to process subfolders:

Option Explicit

Const cOwner = 8

Dim sFolder
Dim i, sHeadings
Dim objFso, objShell
Dim objExcel, objWorkbook, objWorksheet

sFolder = "C:\temp"

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

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")

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

List_Files_In_Folder sFolder, 2

'==============================

Sub List_Files_In_Folder(sFolder, row)

Dim objFolder, objFiles, objFile, objSubFolder
Dim objShFolder, objItem

'Get properties of files in folder

Set objFolder = objFso.GetFolder(sFolder)
Set objFiles = objFolder.Files

Set objShFolder = objShell.Namespace(sFolder)

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

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

'Process subfolders recursively

For Each objSubFolder In objFolder.SubFolders
List_Files_In_Folder objSubFolder.Path, row
Next

End Sub



Re: owner propety on files by JayJ

JayJ
Thu Sep 06 08:14:07 PDT 2007

Thank you again for all the help and the links. You are right, the references
I find also show the constant as 8 for owner. I am using xp and 8 is
outputing file size in kb and 12 is outputting owner. Not a big issue. Just
wanted to let you know...

"John W" wrote:

>
> "JayJ" <JayJ@discussions.microsoft.com> wrote in message news:50EB74C4-870B-41C2-8977-0482ED27281E@microsoft.com...
> >
> >> 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...
>
> Which OS are you using? Both the references I found say it's 8 for Windows 2000, XP and 2003:
>
> http://classicasp.aspfaq.com/files/directories-fso/how-do-i-find-the-owner-author-and-other-properties-of-a-file.html
>
> http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_lunl.mspx?mfr=true
>
> >>
> > 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..
>
> Sure. Put the file processing in a subroutine and call it recursively for each subfolder. A quick Google shows the technique:
>
> http://groups.google.co.uk/group/microsoft.public.scripting.vbscript/browse_frm/thread/ae0662d14038c45b/f3ad5006efe5fb5b?lnk=gst&q=recursive+folders&rnum=2#f3ad5006efe5fb5b
>
> Here's my modified script to process subfolders:
>
> Option Explicit
>
> Const cOwner = 8
>
> Dim sFolder
> Dim i, sHeadings
> Dim objFso, objShell
> Dim objExcel, objWorkbook, objWorksheet
>
> sFolder = "C:\temp"
>
> sHeadings = Array("File Name", "File Path", "File Size in Bytes" ,_
> "Date Created", "Last Accessed", "Last Modified", "Owner")
>
> Set objFso = CreateObject("Scripting.FileSystemObject")
> Set objShell = CreateObject("Shell.Application")
>
> 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
>
> List_Files_In_Folder sFolder, 2
>
> '==============================
>
> Sub List_Files_In_Folder(sFolder, row)
>
> Dim objFolder, objFiles, objFile, objSubFolder
> Dim objShFolder, objItem
>
> 'Get properties of files in folder
>
> Set objFolder = objFso.GetFolder(sFolder)
> Set objFiles = objFolder.Files
>
> Set objShFolder = objShell.Namespace(sFolder)
>
> For Each objFile In objFiles
> Set objItem = objShFolder.ParseName(objFile.Name)
>
> With objWorksheet
> .Cells(row,1).Value = objFile.Name
> .Cells(row,2).Value = objFile.ParentFolder
> .Cells(row,3).Value = objFile.Size
> .Cells(row,4).Value = objFile.DateCreated
> .Cells(row,5).Value = objFile.DateLastAccessed
> .Cells(row,6).Value = objFile.DateLastModified
> .Cells(row,7).Value = objShFolder.GetDetailsOf(objItem, cOwner)
> End With
> row = row + 1
> Next
>
> 'Process subfolders recursively
>
> For Each objSubFolder In objFolder.SubFolders
> List_Files_In_Folder objSubFolder.Path, row
> Next
>
> End Sub
>
>
>

Re: owner propety on files by Gill

Gill
Thu Sep 06 10:34:40 PDT 2007

There is a product called Varonis DatAdvantage that uses an agent to collect
all the who/when/where activities on monitored files/folders. I would like
to see if I can emulate that using a WMI event sync. The script below is a
good reference, but I would like to somehow capture who created the file,
and tag the file with that info. I'm going with the assumption that "owner"
and "file creator" can be different.

Does anyone think this is possible? I'm guessing the script would fire on
file creation (which is probably when the file actually gets saved), but I'm
not sure there will be a file lock issue.

Or I could at least keep a database updated of who created a file. Then I
would probably expand the script to detect reads/writes/archive bit
changes/etc...

Gill


On 9/6/07 11:14 AM, in article
4F6D5324-0F5B-4E18-8024-0246566AC633@microsoft.com, "JayJ"
<JayJ@discussions.microsoft.com> wrote:

> Thank you again for all the help and the links. You are right, the references
> I find also show the constant as 8 for owner. I am using xp and 8 is
> outputing file size in kb and 12 is outputting owner. Not a big issue. Just
> wanted to let you know...
>
> "John W" wrote:
>
>>
>> "JayJ" <JayJ@discussions.microsoft.com> wrote in message
>> news:50EB74C4-870B-41C2-8977-0482ED27281E@microsoft.com...
>>>
>>>> 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...
>>
>> Which OS are you using? Both the references I found say it's 8 for Windows
>> 2000, XP and 2003:
>>
>> http://classicasp.aspfaq.com/files/directories-fso/how-do-i-find-the-owner-au
>> thor-and-other-properties-of-a-file.html
>>
>>
http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_lunl.mspx?mfr=tru>>
e
>>
>>>>
>>> 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..
>>
>> Sure. Put the file processing in a subroutine and call it recursively for
>> each subfolder. A quick Google shows the technique:
>>
>> http://groups.google.co.uk/group/microsoft.public.scripting.vbscript/browse_f
>> rm/thread/ae0662d14038c45b/f3ad5006efe5fb5b?lnk=gst&q=recursive+folders&rnum=
>> 2#f3ad5006efe5fb5b
>>
>> Here's my modified script to process subfolders:
>>
>> Option Explicit
>>
>> Const cOwner = 8
>>
>> Dim sFolder
>> Dim i, sHeadings
>> Dim objFso, objShell
>> Dim objExcel, objWorkbook, objWorksheet
>>
>> sFolder = "C:\temp"
>>
>> sHeadings = Array("File Name", "File Path", "File Size in Bytes" ,_
>> "Date Created", "Last Accessed", "Last Modified", "Owner")
>>
>> Set objFso = CreateObject("Scripting.FileSystemObject")
>> Set objShell = CreateObject("Shell.Application")
>>
>> 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
>>
>> List_Files_In_Folder sFolder, 2
>>
>> '==============================
>>
>> Sub List_Files_In_Folder(sFolder, row)
>>
>> Dim objFolder, objFiles, objFile, objSubFolder
>> Dim objShFolder, objItem
>>
>> 'Get properties of files in folder
>>
>> Set objFolder = objFso.GetFolder(sFolder)
>> Set objFiles = objFolder.Files
>>
>> Set objShFolder = objShell.Namespace(sFolder)
>>
>> For Each objFile In objFiles
>> Set objItem = objShFolder.ParseName(objFile.Name)
>>
>> With objWorksheet
>> .Cells(row,1).Value = objFile.Name
>> .Cells(row,2).Value = objFile.ParentFolder
>> .Cells(row,3).Value = objFile.Size
>> .Cells(row,4).Value = objFile.DateCreated
>> .Cells(row,5).Value = objFile.DateLastAccessed
>> .Cells(row,6).Value = objFile.DateLastModified
>> .Cells(row,7).Value = objShFolder.GetDetailsOf(objItem, cOwner)
>> End With
>> row = row + 1
>> Next
>>
>> 'Process subfolders recursively
>>
>> For Each objSubFolder In objFolder.SubFolders
>> List_Files_In_Folder objSubFolder.Path, row
>> Next
>>
>> End Sub
>>
>>
>>