Note that there are some explanatory texts on larger screens.

plurals
  1. POVBS: FileSystemObject use in Recursion
    primarykey
    data
    text
    <p>Currently I'm working on a script that will go through a given folder and search for all files with a specific extension. It will then print out the name and sum the file size. I believe i have most of the issues sorted out, so this question isn't about how to do this.</p> <p>Instead, I want to know what would be the best practice for using FileSystemObject streams in a recursive function. Should I be using a single stream for all calls (either global, or passed), or should I be creating a new stream for each recursive step?</p> <p>For extra fun, I'm planning on having this access multiple PCs, and over UNC path. And yes, I expect there's a better way of doing this, but I'm relatively new with VBS.</p> <p>Current code:</p> <pre><code>'Recursive Function handles search of files in folder and subfolders. Function UNCSearchFolder(strUNCRootPath, strUNCNextFolder) Dim objFSOUNCSearchFolder, objFSOUNCSearchFolder2, colFolderList, objFolder, strCurrentFolder, strSubFolder 'Get list of Subfolders in folder: &lt;Rootpath&gt;\&lt;Nextfolder&gt; strCurrentFolder = strUNCRootPath &amp; "\" &amp; strUNCNextFolder &amp; "\" Set objFSOUNCSearchFolder = CreateObject("Scripting.FileSystemObject") Set objFSOUNCSearchFolder2 = objFSOUNCSearchFolder.GetFolder(strCurrentFolder) Set colFolderList = objFSOUNCSearchFolder2.SubFolders 'Subfolder dive For Each objFolder in colFolderList strSubFolder = objFolder.name 'REMOVE THIS ECHO LATER wscript.echo strSubFolder UNCSearchFolder(strCurrentFolder, strSubFolder) Next 'Search for files here 'GC on File Streams Set objFSOUNCSearchFolder2 = Nothing Set objFSOUNCSearchFolder = Nothing End Function </code></pre> <p>So, should one filestream be used for all accesses or should each step use one separately? Is it a moot point? Will this cause multiple connections to each system or should it only use one? Basically I want the script to work without disrupting users, or causing weird responses (ie, running out of active connections). The script will only be used a couple times for an audit we're doing, but may eventually be repurposed for future audits.</p> <p>Let me know what you think. Thanks for any help,</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.
 

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