Re: script to find all files in folder/subfolders



As I mentioned before: This type of task is easily handled by
existing Command Line commands. Unless you have a strong
reason to re-invent the wheel in VB Script, using a batch file
is the usual solution. Try this one:

@echo off
set Age=365
robocopy d:\temp d:\HoldingPen *.txt /S /move /MinAge:%Age% > c:\Move.txt

You can download robocopy.exe from here:
download:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en


"speedstic" <speedstic@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:792AFB69-6EDE-4DA6-BBBE-BF85DFC245D1@xxxxxxxxxxxxxxxx
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

  • Accesing structures data (getting lengthy!)
    ... > assignment statement just won't stand out amongst all the other ... > meaningless dummy variables that you have to keep track of. ... > comparitively easy to pick out of a long, boring, command line history, ... > original, for some reason, wraps me up in knots. ...
    (comp.soft-sys.matlab)
  • Re: My Weekly Drash - Vayera
    ... you're asking what reason there might be for a ... >> literally speaking in one voice) and concluding that the law had never ... I have problem with that understanding, ... Because when the command _to him_ is to do ...
    (soc.culture.jewish.moderated)
  • Re: My Weekly Drash - Vayera
    ... >>> while I said I prefer to know the purpose of a law. ... > a reason. ... >> impart a reson to G-d's command. ... Moshe Schorr ...
    (soc.culture.jewish.moderated)
  • Re: Some Comments on an "Adventure Engine"
    ... a brass lantern with rusted hinges. ... So there is no reason to deal with explicit numeric equivalences. ... If you're expecting the player to enter these numeric values ... instead of typing a command (gee, ...
    (alt.lang.asm)
  • Re: Script to Search and Delete Files from Remote Machines
    ... I said it in a previous thread and forgot to mention it again, the command should be saved in a batch file. ... finally i made one script and able to delete file using LIKE. ... Set colFiles = objWMIService.ExecQuery _ ... Dim strComputer, strExtension, oLog, colFiles, objWMIService, _ ...
    (microsoft.public.windows.server.scripting)