script to find all files in folder/subfolders



Hello All,

I am trying to write a script to generate a log of all the files in a
folder, including sub-folders but I can't get the subfolder part to work.
Here is what i have so far...
--beginning--
strComputer = "."
logFile = "c:\test.txt"
count = 0

Const ForWriting = 2
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCreateFile = objFSO.CreateTextFile(LogFile)
objCreateFile.Close
Set objCreateFile = objFSO.OpenTextFile(LogFile, ForWriting)
objCreateFile.WriteLine "Starting search at " & date() & ", " & time() & "..."
objCreateFile.Close

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

Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='c:\test\'} Where " _
& "ResultClass = CIM_DataFile")

For Each objFile In colFileList
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile")
file_name = "Filename: " & objFile.Name
last_access = " Last Modified: " & objFile.LastModified
file_size = "Size: " & objFile.FileSize
count = count+1
Set objEditFile = objFSO.OpenTextFile(LogFile, ForAppending)
objEditFile.WriteLine count & ": " & file_name & ", " & last_access & ", "
& file_size
objEditFile.Close
Next

Wscript.Echo count
--end--

It works for finding the files in a folder, but not the files inside
subfolders.
Any help would be greatly appreciated!
.



Relevant Pages

  • Re: script to find all files in folder/subfolders
    ... folder, including sub-folders but I can't get the subfolder part to work. ... Set colFiles = objWMIService.ExecQuery _ ... good reason to use a VB Script to perform the task. ...
    (microsoft.public.windows.server.scripting)
  • Re: RDO objects and C#
    ... OutlookSpy - Outlook, CDO ... The error occurs after reading say around 700/800 emails in one folder. ... RDOFolder rdoFolder = rdoFolders.GetFirst; ... RDOFolder subFolder; ...
    (microsoft.public.outlook.interop)
  • Re: Sent Items still MIA, tried importing from .dbx
    ... and the subfolder itself in OE. ... If I somehow dragged my entire Sent Items folder to the Deleted Items ... e-mails except for those I specifically physically move into it, ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Permission problem - URGENT !
    ... UsersB has no permission of Filex down in some ... subfolder, so you go to that file and add a grant of Read ... shortcut from your .\desktop folder to the .\desktop folder ... > parent folder/subfolder/files. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: linking to pub files in more languages
    ... The German version of your site is not in a subfolder called "deutsch". ... You do not say how you are uploading your files to your host. ... at the same level as the current index_files folder, ...
    (microsoft.public.publisher.webdesign)

Loading