I have a script that will recursively output all files, paths and file
properties to an excel spreadsheet. I want to modify it to find and output
only .mdb or ldb files. It is probably simple but i cant figure out where to
put in the logic for the "Where extension = 'adb' or ldb" type of command or
maybe I have to use GetExtensionName method?

Any help to modify the scipt below is appreciated

***********************************************************

' steps recursively through folder and outputs all files, file sizes etc.

Option Explicit

Const cOwner = 12

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

sFolder = "\\Server\groups2\BusinessIntelligence\"

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:\spreadsheet.xls")
Set objWorksheet = objWorkbook.Worksheets(1)

i = 2

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)


With objWorksheet
.Cells(row,1).Value = objFile.Name
.Cells(row,2).Value = objFile.ParentFolder
.Cells(row,3).Value = objShFolder.GetDetailsOf(objItem,8)
.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: Find all access database by Rafael

Rafael
Thu Dec 06 18:11:57 PST 2007

Jay,

I bet you can find what you need in this link
http://www.microsoft.com/technet/scriptcenter/resources/begin/ss0607.mspx

WMI is very powerful in finding the files you need and should not be too
complicated.

--
**********
Rafael T


"JayJ" <JayJ@discussions.microsoft.com> wrote in message
news:C36BE674-7E22-4F06-9419-ECBB60FAA960@microsoft.com...
>I have a script that will recursively output all files, paths and file
> properties to an excel spreadsheet. I want to modify it to find and output
> only .mdb or ldb files. It is probably simple but i cant figure out where
> to
> put in the logic for the "Where extension = 'adb' or ldb" type of command
> or
> maybe I have to use GetExtensionName method?
>
> Any help to modify the scipt below is appreciated
>
> ***********************************************************
>
> ' steps recursively through folder and outputs all files, file sizes etc.
>
> Option Explicit
>
> Const cOwner = 12
>
> Dim sFolder
> Dim i, sHeadings
> Dim objFso, objShell
> Dim objExcel, objWorkbook, objWorksheet
>
> sFolder = "\\Server\groups2\BusinessIntelligence\"
>
> 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:\spreadsheet.xls")
> Set objWorksheet = objWorkbook.Worksheets(1)
>
> i = 2
>
> 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)
>
>
> With objWorksheet
> .Cells(row,1).Value = objFile.Name
> .Cells(row,2).Value = objFile.ParentFolder
> .Cells(row,3).Value = objShFolder.GetDetailsOf(objItem,8)
> .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: Find all access database by JayJ

JayJ
Thu Dec 06 18:34:04 PST 2007

Thank you for the response. I have looked at all those scripts - This script
works to find files recursively though folders and output them to a
spreadsheet. I don't to reinvent the wheel and start a script from scratch so
was wondering if anyone could help incorportate something like you pointed
out, in this script. I have been trying but can't get it to work.

Thank you.

"Rafael T" wrote:

> Jay,
>
> I bet you can find what you need in this link
> http://www.microsoft.com/technet/scriptcenter/resources/begin/ss0607.mspx
>
> WMI is very powerful in finding the files you need and should not be too
> complicated.
>
> --
> **********
> Rafael T
>
>
> "JayJ" <JayJ@discussions.microsoft.com> wrote in message
> news:C36BE674-7E22-4F06-9419-ECBB60FAA960@microsoft.com...
> >I have a script that will recursively output all files, paths and file
> > properties to an excel spreadsheet. I want to modify it to find and output
> > only .mdb or ldb files. It is probably simple but i cant figure out where
> > to
> > put in the logic for the "Where extension = 'adb' or ldb" type of command
> > or
> > maybe I have to use GetExtensionName method?
> >
> > Any help to modify the scipt below is appreciated
> >
> > ***********************************************************
> >
> > ' steps recursively through folder and outputs all files, file sizes etc.
> >
> > Option Explicit
> >
> > Const cOwner = 12
> >
> > Dim sFolder
> > Dim i, sHeadings
> > Dim objFso, objShell
> > Dim objExcel, objWorkbook, objWorksheet
> >
> > sFolder = "\\Server\groups2\BusinessIntelligence\"
> >
> > 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:\spreadsheet.xls")
> > Set objWorksheet = objWorkbook.Worksheets(1)
> >
> > i = 2
> >
> > 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)
> >
> >
> > With objWorksheet
> > .Cells(row,1).Value = objFile.Name
> > .Cells(row,2).Value = objFile.ParentFolder
> > .Cells(row,3).Value = objShFolder.GetDetailsOf(objItem,8)
> > .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: Find all access database by Paul

Paul
Thu Dec 06 19:36:55 PST 2007


"JayJ" <JayJ@discussions.microsoft.com> wrote in message
news:C36BE674-7E22-4F06-9419-ECBB60FAA960@microsoft.com...
>I have a script that will recursively output all files, paths and
>file
> properties to an excel spreadsheet. I want to modify it to find and
> output
> only .mdb or ldb files. It is probably simple but i cant figure out
> where to
> put in the logic for the "Where extension = 'adb' or ldb" type of
> command or
> maybe I have to use GetExtensionName method?
>
> Any help to modify the scipt below is appreciated
>
> ***********************************************************
>
> ' steps recursively through folder and outputs all files, file sizes
> etc.
>
> Option Explicit
>
> Const cOwner = 12
>
> Dim sFolder
> Dim i, sHeadings
> Dim objFso, objShell
> Dim objExcel, objWorkbook, objWorksheet
>
> sFolder = "\\Server\groups2\BusinessIntelligence\"
>
> 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:\spreadsheet.xls")
> Set objWorksheet = objWorkbook.Worksheets(1)
>
> i = 2
>
> 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)
>
>
> With objWorksheet
> .Cells(row,1).Value = objFile.Name
> .Cells(row,2).Value = objFile.ParentFolder
> .Cells(row,3).Value = objShFolder.GetDetailsOf(objItem,8)
> .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

I think you are missing at least one line in your subroutine.
The first Next statement has no previous For statement. Within that
loop, only add data to your Excel file if the extension matches the
ones you are interested in.

And yes, the objFso.GetExtensionName method can be used to extract the
extension from a string containing a file's name, whether it is a
local path or a URL.
objFso.GetExtensionName(objFile.Name)

-Paul Randall