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
year, then copy the file to a new location before deleting it, while writing
to a txt file which files have been moved, their size, and the number of
files moved.
I haven't been able to move forward since i can't seem to get this part
working.

"Pegasus (MVP)" wrote:


"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: Script: Network share problems
    ... If the folder didn't exist or you did not have security ... you will need to add more error checking to your script. ... objFSO.CopyFile source, dest, OVERWRITE_EXISTING ... ' Delete all files in subfolders ...
    (microsoft.public.windowsxp.wmi)
  • Re: creating folder tree structures
    ... When I have a working script I will post ... Set fso = CreateObject ... So that ONLY "Folder 1" name is ... the rest of the subfolders are set already. ...
    (microsoft.public.scripting.vbscript)
  • Subfolder views
    ... I am trying to make all subfolders in My Pictures the same as the main ... MVP Keith had a script to do the job, ... You can select a folder & configure its view settings, ... non-grouped view to be the default inheritance for My Computer, ...
    (microsoft.public.windowsxp.basics)
  • Re: Customize File Views -HELP!
    ... I've written a script that will apply all the view customizations you can ... You can select a folder & configure its view settings, ... subfolders ...
    (microsoft.public.windowsxp.general)
  • 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)