0 votes

How can I search for folders that contain only an exact number of files defined by me. Or if not possible can I search for folders which contain only the filenames that I define.

by (70 points)
Thank you for your help, the script files works perfectly, exactly what I was looking for.

1 Answer

0 votes

You can do that with a little scripting. Save the script below into a file, e.g. folders_with_filecount.js, then reference it in the scripting tab:

Scripting Tab

The Parm field is used to enter the specific number of files that a folder must contain.

var objFSO = new ActiveXObject( "Scripting.FileSystemObject" );
var nCountFiles = parseInt(SearchParms.FilenameCustomParm);

function isValidFileName( strPath, strFileName )
{
    // Count the number of files in the given folder
    // and check it against the user value.
    
    var bIsValid = false;
    try
    {
        var strFolderPath = strPath + strFileName
        
        if ( objFSO.FolderExists( strFolderPath ) )
        {
            var folderCheck = objFSO.GetFolder( strFolderPath );
            bIsValid = (folderCheck.Files.Count == nCountFiles);            
        }
    }
    catch( e )  {}
    return bIsValid;
}

Note: To make the search faster use the Folders Only drop down option in the Main tab.


You could also search for folders that contain specific files by simply listing them in the file name field and then using the Report Tab to only show the unique folders, e.g.

File name: filename1.dat;filename2.dat;filename3.dat

Or by saving them to a text file and loading them in, e.g.

File name: =C:\MySavedFilenameList.txt
by (83.5k points)
...