Re: script to find all files in folder/subfolders




"speedstic" <speedstic@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4C39387F-4448-46E7-BF69-24B61A2CDF26@xxxxxxxxxxxxxxxx
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!

The first question I would ask in this case is whether there is a
good reason to use a VB Script to perform the task. If there
isn't then this single, simple command line would do the job
very nicely:

dir "c:\program files" /s /ta /a-d | find "/"


.



Relevant Pages

  • Re: One for the NTFS permissions gurus.
    ... user logs-on the script creates a new subfolder based on the username. ... What I want to do is to set the permissions on the parent folder (the shared ... but other users have no rights. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: script to find all files in folder/subfolders
    ... what I would like the script to eventually do, is scan all files in a certain ... folder (including subfolders) and if the file has not been modified in 1 ... folder, including sub-folders but I can't get the subfolder part to work. ... Set colFiles = objWMIService.ExecQuery _ ...
    (microsoft.public.windows.server.scripting)
  • Re: Xcacls - Recusive script on folders and subfolders - Dummy question !!!
    ... > Can you tell me how to change your script to level 2 in folder ... > only (or how to be able to parameter the folder and subfolder level)? ... >> the end) and save the result to a different file for each subfolder. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • script to find all files in folder/subfolders
    ... folder, including sub-folders but I can't get the subfolder part to work. ... Set objCreateFile = objFSO.OpenTextFile ... Set colFiles = objWMIService.ExecQuery _ ...
    (microsoft.public.windows.server.scripting)
  • Re: creating folder tree structures
    ... SUBFOLDER B ... to end the script. ... particular folder structure is setup in our file servers. ... and I think I should get this setup as it's ...
    (microsoft.public.scripting.vbscript)