Re: script to find all files in folder/subfolders
- From: speedstic <speedstic@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 22 Feb 2008 13:25:01 -0800
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 "/"
- Follow-Ups:
- Re: script to find all files in folder/subfolders
- From: urkec
- Re: script to find all files in folder/subfolders
- From: Pegasus \(MVP\)
- Re: script to find all files in folder/subfolders
- References:
- script to find all files in folder/subfolders
- From: speedstic
- Re: script to find all files in folder/subfolders
- From: Pegasus \(MVP\)
- script to find all files in folder/subfolders
- Prev by Date: Re: script to find all files in folder/subfolders
- Next by Date: Re: script to find all files in folder/subfolders
- Previous by thread: Re: script to find all files in folder/subfolders
- Next by thread: Re: script to find all files in folder/subfolders
- Index(es):
Relevant Pages
|