Re: script to find all files in folder/subfolders



"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
.



Relevant Pages

  • RE: Newbie: Edit only files with a certain extension in a given folder?
    ... you can use either FileSystemObject or WMI to enumerate all the files with a certain extension in a given folder. ... I would prefer the WMI method as it gives you great control on what you are searching for. ... 'Get the current string and the replacement string from the user... ...
    (microsoft.public.scripting.wsh)
  • Re: VBA, OCX and system folders
    ... Here's some sample code of how to use WMI to get you a listing of files ... > try to use it within VBA and Microsoft Word it fails. ... > Another folder that it cannot get access to is the users temporary ...
    (microsoft.public.word.vba.beginners)
  • RE: WinMgmt could not initialize the core parts
    ... I deleted the wrong folder. ... BUT I'm still getting other WMI type errors. ... Event Type: Error ... Windows couldn't log the RSoP session status. ...
    (microsoft.public.windows.server.general)
  • Restoring WMI
    ... My WMI functionality is not working correctly. ... Windows suggest to correct ... \System32\Wbem\Repository folder become corrupted. ... In the right pane of the Computer Management console, ...
    (microsoft.public.windowsxp.wmi)
  • Re: Alternative to reading public folders with WMI?
    ... > If you want to speed up your WMI queries you should look at making the ... > you methods to a recursively do a shallow traversal of a folder hierarchy ... > public folder tree and instead of working out the foldersize get it to ... >> Does anyone know if there is an alternative to reading Exchange 2003 ...
    (microsoft.public.exchange.development)