"Dan Payne" <grumpyoldb@xxxxxx> wrote in message
news:uwb9ULR6JHA.1092@xxxxxx
>I have no experience with VB scripting, so of course I was asked to
> write one....
> Here's the question.
> Is there any VB code out there that is available for public use that
> would scan directories, and return information such as full path,
> extension, owner, file size, etc out there that I could use??? I signed
> up for a class on VBscripting, but they have postponed it twice so far
> this year, and my deadline is coming up soon. This is probably the
> easiest thing to do, and if it was C or Pascal (showing my age) it would
> be easy, but we don't have those compilers available at work....
>
> Thanks for any help, and not laughing too hard... ;-) Here is a script that should help get you going.
Note that Shell.Application folders are a completely different beast from
File System folders. Shell.Application folders represent the folder windows
that you see on your screen.
Note that the columns displayed in a folder window are specific to that
folder. Most folders have a standard set of columns, some have different
specific sets, and a few have to include all the columns of the others --
the recycle bin, for instance. Windows Search windows and the Temporary
Internet Files folders have some specialized columns, such as 'In Folder',
and URL.
You will probably want the main program to call a recursable
function/subroutine to recurse through all folder levels from your starting
folder.
Option Explicit
Dim oShellApp, oShFlder, oShFldrItem
Set oShellApp = CreateObject("Shell.Application")
'Can access just about any folder window that
' you can see on your screen.
Set oShFlder = oShellApp.NameSpace("C:\scratch")
' or ...
Const RECYCLE_BIN = &hA&
Set oShFlder = oShellApp.Namespace(RECYCLE_BIN)
'or even a WXP file search window with a few
' more lines of code....
For Each oShFldrItem In oShFlder.Items
WScript.Echo ListDic(GetColumnValues(oShFldrItem))
WScript.Echo
Next
WScript.Echo "Done"
Function ListDic(oDic)
Dim sMsg, Key, sCRLF
For Each Key In odic.Keys
sMsg = sMsg & sCRLF & Key & ":" & vbTab & oDic(Key)
sCRLF = vbCrLf
Next 'Key
ListDic = sMsg
End Function 'ListDic(oDic)
Function GetColumnNames(oShellFolder)
'Returns an dictionary where keys are column names
' and items are column numbers (zero based).
Dim oDic, i, sDetail
Set oDic = CreateObject("Scripting.Dictionary")
oDic.CompareMode = vbTextCompare
'Iterate possible columns by numeric index
'I'm just guessing as to the legal range of
' column numbers
For i = -128 To 127
sDetail = oShellFolder.GetDetailsOf(Empty, i)
If Len(sDetail) > 0 Then
oDic(sDetail) = i
End If
Next
Set GetColumnNames = oDic
End Function 'GetColumnNames(oShellFolder)
Function GetColumnValues(oShellFolderItem)
'Returns an dictionary where keys are column names
' and items are the text value for that item in that
' column, followed by a tab character and the column
' number (zero based).
'For example, the first column is typically the item
' name, so the first entry in the dictionary would
' be key "Name", item "itemNameVbTab0"
'Some folders, such as the recycle bin) can hold a
' wide variety of files, and
' have a long list of columns to handle that variety.
' Individual files seldom have values for all of
' those columns.
Dim oDic, sDetail, oDicNames, sName, oShFldr
Set oDic = CreateObject("Scripting.Dictionary")
oDic.CompareMode = vbTextCompare
Set oShFldr = oShellFolderItem.Parent
Set oDicNames = GetColumnNames(oShFldr)
'Iterate possible columns by numeric index, putting
' only those with a value for the column into the
' dictionary.
For Each sName In oDicNames
sDetail = oShFldr.GetDetailsOf _
(oShellFolderItem, oDicNames(sName))
If Len(sDetail) > 0 Then
oDic(sName) = sDetail & vbTab & oDicNames(sName)
End If
Next
Set GetColumnValues = oDic
End Function 'GetColumnValues(oShellFolderItem)
-Paul Randall