Re: script to find all files in folder/subfolders
- From: urkec <urkec@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 23 Feb 2008 08:56:01 -0800
"speedstic" wrote:
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.
If you want to use VBScript and WMI for this you need to use a recursive
function. Here is a sample:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Call ListFiles ("C:\scripts")
'*************************************************
Sub ListFiles (strFolderName)
Set ChildItemList = objWMIService.ExecQuery _
("Associators Of {Win32_Directory.Name=""" _
& Replace (strFolderName, "\", "\\") _
& """} Where Role = GroupComponent")
For Each objItem in ChildItemList
If objItem.Path_.Class = "Win32_Directory" Then
Call ListFiles (objItem.Name)
WScript.Echo "Folder" & objItem.Name
ElseIf objItem.Path_.Class = "CIM_DataFile" Then
WScript.Echo "File " & objItem.Name
End If
Next
End Sub
There is also a sample here, maybe you can use it:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/hey0405.mspx
Is there a reason you want to use WMI for this? The command line option does
look simpler.
--
urkec
.
- References:
- script to find all files in folder/subfolders
- From: speedstic
- Re: script to find all files in folder/subfolders
- From: Pegasus \(MVP\)
- Re: script to find all files in folder/subfolders
- From: speedstic
- script to find all files in folder/subfolders
- Prev by Date: Re: Writing to a text file
- Next by Date: Re: Script to logoff XP systems after inactivity
- Previous by thread: Re: script to find all files in folder/subfolders
- Next by thread: Re: Script to logoff XP systems after inactivity
- Index(es):
Relevant Pages
|