Jscript enumerating items and completely skip certain folders

So I am creating a jscript and during enumeration, I wonder if there is a way to 'intercept ' the enumeration to completely skip certain folders. I know i can check is_dir and continue, but that then continues (i think) into the folder and continues enumerating the folder's contained files.

So I want to bypass even ENTERING certain folders

Thx

Hard to say without seeing some actual code.

Enumerate the folder non-recursively and dive into subfolders only as needed.

1 Like

Sounds like a plan - but that only works if the folder (within the collection) does not contain more subfolders (that's my thinking...).

here is the code, although I dont think what I want is possible. I have a

collectionEnum.Skip()

in there although I know its not a valid method.

function Z_collectForFuzzyDupeSearchLEO(scriptCmdData) {
	DOpus.Output('RUNNIGN Z_collectForFuzzyDupeSearchLEO ================================');
	
	var collectionEnum = DOpus.FSUtil.ReadDir('coll://PRINT_coll', true);
	// var outputFile = DOpus.FSUtil.OpenFile('C:\\AMD\\filepaths.txt', 'w');
	
	var allowItem = null;

	var filesAddedCount = 0;
	var filesAddedMax = 30000;
	
	var filesScannedCount = 0;
	var filesScannedMax = 1000;

	var foldersScannedCount = 0;
	var testIsDir, testFldName, testExt, testName, testMaxWirtten

	// tests to see which items are actually copied to new collection
	var regFolders = /(USA|CANADA|EUROPE|AFRICA)/i;
	var regExt = /\.(txt|zip|jpe?g|ini|pdf|tmp)$/i;
	var regFN = /-(1080|720|480|360)p?/

	// enumerate the source collection
	while (!collectionEnum.complete) {
		var nextItem = collectionEnum.Next();

		if (nextItem.is_dir && regFolders.test(nextItem.Name)) {
			DOpus.Output('SKIPPING FOLDER AND CONTENTS?:\n' + nextItem.Name);
			collectionEnum.Skip(); // Skip the folder and its contents completely
			foldersScannedCount++;
			continue;
		} else if (nextItem.is_dir){
			DOpus.Output('SKIPPING FOLDER: ' + nextItem.Name);
			filesScannedCount++; 
			continue;   //this will only skip the folder but NOT ITS contents
		}


		// test various conditions
		testIsDir = nextItem.is_dir
		testFldName = regFolders.test(nextItem.path)
		testExt = regExt.test(nextItem.ext)
		testName = regFN.test(nextItem.Name)
		testMaxWirtten = filesAddedCount >= filesAddedMax
		
		allowItem = !testIsDir && testName && !testFldName && !testExt  && testMaxWirtten

		if (allowItem) {
			scriptCmdData.func.command.RunCommand('COPY TO coll://DUPES"' + nextItem.RealPath + '" "' + nextItem.Name + '"');
			filesAddedCount++;
		}

		if (filesScannedCount >= filesScannedMax) break;

	} 


}  	// END OF Z_collectForFuzzyDupeSearchLEO FUNCTION ===================================================

You can move the enumeration to a function and have it call itself, effectively creating recursion. Not sure if it's worth the trouble.

1 Like

thx - I think your write - not worth it