Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Start with a skeleton script that traverses a folder tree:</p> <pre><code>Step00.vbs: Option Explicit Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject") WScript.Quit Main() Function Main() Dim sDir : sDir = "..\test" Dim oWorker : Set oWorker = New cWorker Main = traverseDir(goFS.GetFolder(sDir), oWorker) End Function Class cWorker Public Sub processFile(oFile) WScript.Echo oFile.Path End Sub End Class Function traverseDir(oDir, oWorker) traverseDir = 0 Dim oF For Each oF In oDir.Files oWorker.processFile oF Next For Each oF In oDir.SubFolders traverseDir = traverseDir(oF, oWorker) Next End Function </code></pre> <p>Output:</p> <pre><code>cscript step00.vbs E:\trials\SoTrials\answers\13415663\test\13415663.notes E:\trials\SoTrials\answers\13415663\test\13415663.kpf E:\trials\SoTrials\answers\13415663\test\13415663-UE15.prj E:\trials\SoTrials\answers\13415663\test\vbs\step00.vbs </code></pre> <p>The Main function passes a folder and a worker to the traverseDir function and returns an exit code to be passed to the caller (OS). The traverseDir function sends each file in a directory to the worker's processFile sub, call itself recursively for each subfolder, and returns an error code to the caller (Main/previous instance of itself). The (trivial) worker just echos the file's path.</p> <p>Step01.vbs uses a worker with a hardcoded condition to determine which files to delete:</p> <pre><code>Class cWorker Public Sub processFile(oFile) If "notes" = goFS.GetExtensionName(oFile.Name) Then WScript.Echo "will delete", oFile.Path oFile.Delete End If End Sub End Class </code></pre> <p>output:</p> <pre><code>cscript step01.vbs will delete E:\trials\SoTrials\answers\13415663\test\13415663.notes </code></pre> <p>Based on this proof of concept script you can enhance the traverseDir function (error handling for not accessible folders, ...) and/or the cWorker class (more complex condition, error handling, logging, ...).</p> <p><strong>Update:</strong></p> <p>See <a href="https://stackoverflow.com/a/13429422/603855">this recursive folder access script</a> to get ideas for further enhancements of the skeleton.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload