0 votes

Let's say that on a disk I have some mp4 files, and some of those files have an associated jpg file (same filename and extension), e.g.

file1.mp4

file2.mp4
file2.mp4.jpg

file3.mp4

file4.mp4

file5.mp4
file5.mp4.jpg

Is it possible to run a search to find only the files that have (*.mp4 AND *.mp4.jpg)?
So the result would show:

file2.mp4
file2.mp4.jpg
file5.mp4
file5.mp4.jpg
by (50 points)

1 Answer

+1 vote
 
Best answer

If you wanted to just find .mp4 and .mp4.jpg files then the simplest option would be to search for:

*.mp4;*.mp4.jpg

However, to search for file names based on other names in the folder would require the above search PLUS scripting, such as:

// This script returns all files with an associated file.
	
var objFSO = new ActiveXObject( "Scripting.FileSystemObject" );

function isValidFileName( strPath, strFileName )
{
	// Look to see if a file exists with the same name but with an additional extension.
	
	var bIsValid = false;
	try
	{
		bIsValid = objFSO.FileExists( strPath + strFileName + SearchParms.FilenameCustomParm ) ||
			(strFileName.indexOf(SearchParms.FilenameCustomParm) > 0);
	}
	catch( e )	{}
	return bIsValid;
}

Step 1. Save the above text to a file, e.g. folder_contains_assocfile.js

Step 2. Reference the file in the Scripting tab and enter the additional extension, ie. .jpg

Associated file script

Step 3. Search for both the file types, ie. *.mp4;*.mp4.jpg

Search for both file types

You should find that the pairs of files now appear.

For more information on scripting please see:
https://help.mythicsoft.com/filelocatorpro/v9/en/scripting.htm

by (31.4k points)
Question updated.
Ah, yes, I understand now. Please see modified answer.
Sorry but it is not yet clear, in my case, what I have to insert in the fields.
Answer now includes, script and steps to run search.
Everything is OK, so I thank you for your patience and support.
What changes must be done to the script if, in the case said above, one has to search:
- filename.mp4
- filename.mp4.jpg
- filename,mp4.webp

All three.
In this case, the search has to find .jpg but also .webp (that is at the same "level" and not "one level above" like .mp4 with reference to .mp4.jpg)
I would probably change the script to use fixed values rather than using SearchParms.FilenameCustomParm. e.g. objFSO.FileExists( strPath + strFileName + ".jpg") || objFSO.FileExists( strPath + strFileName + ".webp") || ...
I found a more clean solution leaving the SearchParms and adding
|| objFSO.FileExists( strPath + strFileName.substring(0,strFileName.length - 4) + SearchParms.FilenameCustomParm )
to your script.
In my particular case the decision is made on the presence of .webp (that must be inserted in the "Parm" field)
So the script is this one, that I share in case someone else is interested

// This script returns all files with an associated file.
   
var objFSO = new ActiveXObject( "Scripting.FileSystemObject" );

function isValidFileName( strPath, strFileName )
{
    // Look to see if a file exists with the same name but with an additional extension.
   
    var bIsValid = false;
    try
    {
        bIsValid = objFSO.FileExists( strPath + strFileName + SearchParms.FilenameCustomParm ) || (strFileName.indexOf(SearchParms.FilenameCustomParm) > 0) || objFSO.FileExists( strPath + strFileName.substring(0,strFileName.length - 4) + SearchParms.FilenameCustomParm );
    }
    catch( e )    {}
    return bIsValid;
}

Thanks again and stay well
...