Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to list extended file info? 1

Status
Not open for further replies.

jfdabiri

MIS
Feb 27, 2007
282
US
i have this script:
Code:
strDir = "c:\a_a\"
 
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir) 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strdir)
  
For Each strFileName in objFolder.Items
msg= msg & _ 
  objFolder.GetDetailsOf(strFileName, 0) & vbtab & _
  objFolder.GetDetailsOf(strFileName, 1) & vbtab & _
  objFolder.GetDetailsOf(strFileName, 8) & vbcrlf   
Next
msgbox msg

it displays the contents of only one directory. is there anyway to get it to drill into every directory in that folder, and list the files in subsequent subfolders?
thanks.
 
Already tons of threads here about recursive folder search.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
true, but they reference different objects that namespace doesn't co-exist with.
thanks.
 
For each FSO.Folder object found you reset the NameSpace object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
phv,
the first iteration of the sub works. it lists the files and properties.
then in the second part, where i call the sub again, it pukes.
 
here's the code that i have:
Code:
strDir = "c:\a_a\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strdir)

getInfo(objDir)

Sub getInfo(pCurrentDir)

For Each aItem In pCurrentDir.Files
    
  For Each strFileName in objFolder.Items
  
     msg = msg & _ 
        objFolder.GetDetailsOf(strfilename, 0) & vbtab & _
        objFolder.GetDetailsOf(strfilename, 1) & vbtab & _
        objFolder.GetDetailsOf(strfilename, 8) &  vbcrlf
                
  next   
   
Next
 
  msgbox msg  

For Each aItem In pCurrentDir.SubFolders
    
   Set objShell = CreateObject("Shell.Application")
   Set objFolder = objShell.Namespace(aitem)
 
   getInfo(aItem)
Next 

End Sub
 
What about this (typed, untested) ?
Code:
strDir = "c:\a_a\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
getInfo(strDir)

Sub getInfo(pCurrentDir)
Set objDir = FSO.GetFolder(pCurrentDir)
Set objFolder = objShell.Namespace(pCurrentDirr)
For Each strFileName in objFolder.Items
  msg = msg & _ 
   objFolder.GetDetailsOf(strfilename, 0) & vbtab & _
   objFolder.GetDetailsOf(strfilename, 1) & vbtab & _
   objFolder.GetDetailsOf(strfilename, 8) &  vbcrlf
Next
MsgBox msg  
For Each aItem In objDir.SubFolders
  getInfo(aItem)
Next 
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
it errors out on this line:
For Each strFileName in objFolder.Items
 
Any chance you could post the error message ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How about this?

Code:
Option Explicit

Main()

Sub Main
	Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
	Dim objDict : Set objDict = CreateObject("Scripting.Dictionary")
	Dim objShell : Set objShell = CreateObject("Shell.Application")
	GetFileInfo objDict, objFSO, objShell, "C:\temp"
	WScript.Echo Join(objDict.Items, VbCrLf)
End Sub

Sub GetFileInfo(objDict, objFSO, objShell, strPath)
	Dim objSFolder : Set objSFolder = objShell.NameSpace(strPath)
	Dim objFolder : Set objFolder = objFSO.GetFolder(strPath)
	
	Dim objFile, objSFile
	For Each objFile In objFolder.Files
		Set objSFile = objSFolder.ParseName(objFile.Name)
		objDict.Add objDict.Count, objSFolder.GetDetailsOf(objSFile, 0) & vbtab & _
						           objSFolder.GetDetailsOf(objSFile, 1) & vbTab & _
						           objSFolder.GetDetailsOf(objSFile, 8)
	Next
	
	Dim objSubFolder
	For Each objSubFolder In objFolder.SubFolders
		GetFileInfo objDict, objFSO, objShell, objSubFolder.Path
	Next
End Sub

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
phv, here's the error
line 9 (below):
For Each strFileName in objFolder.Items

ERROR msg:
object required: 'objfolder
800A01A8

 
dm,
it seems like it works. is there any way to list the full path of each file ending with the file name and ext?
thanks.
 
Sorry for the typo.
Replace this:
Set objFolder = objShell.Namespace(pCurrentDirr)
with this:
Set objFolder = objShell.Namespace(pCurrentDir)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You mean like this....


Code:
Option Explicit

Main()

Sub Main
    Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim objDict : Set objDict = CreateObject("Scripting.Dictionary")
    Dim objShell : Set objShell = CreateObject("Shell.Application")
    GetFileInfo objDict, objFSO, objShell, "C:\temp"
    WScript.Echo Join(objDict.Items, VbCrLf)
End Sub

Sub GetFileInfo(objDict, objFSO, objShell, strPath)
    Dim objSFolder : Set objSFolder = objShell.NameSpace(strPath)
    Dim objFolder : Set objFolder = objFSO.GetFolder(strPath)
    
    Dim objFile, objSFile
    For Each objFile In objFolder.Files
        Set objSFile = objSFolder.ParseName(objFile.Name)
        objDict.Add objDict.Count, objFile.Path & vbtab & _
                                   objSFolder.GetDetailsOf(objSFile, 1) & vbTab & _
                                   objSFolder.GetDetailsOf(objSFile, 8)
    Next
    
    Dim objSubFolder
    For Each objSubFolder In objFolder.SubFolders
        GetFileInfo objDict, objFSO, objShell, objSubFolder.Path
    Next
End Sub

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top