0 votes

I've spent the last week learning JScript and I felt I had a pretty good feel for it, but, I've written a JScript for FLP and it doesn't return any info, so I don't have as good a feel as I thought.

I'm very interested in finding a JScript programming environment so I can debug to find out where I made my mistake. I learn as much through debugging as by reading. Every language I've ever programmed in I've been lucky enough to have debugging capabilities.

Any thoughts and/or recommendations will be greatly appreciated.

Thank you for your time and effort,
Mike

Edit: I posted this months ago, then hid it after a week or so with no response (I thought I'd asked a really stupid question or something). I was hoping someone would have an idea of a debugger or IDE I could use for debugging. I've written several programs and its been all trial and error, since FLP gives little or no feedback when it can't do something I've asked it to do.

But, I can still use some help finding a JScript of JavaScript that works with ActiveX object, so can't be used to debug FileSystemObjects. There are many debuggers out there like that, so If anyone thinks of a debugger that can do FileSystemObjects, please hit me up.

by (225 points)

1 Answer

0 votes

It seems no one has a debugger that they use. Here is an answer that I came up with: I write to a text file to check the results of changes to my code.

The one that follows illustrates this. But first a description of my needs.

I have a very large movie collection. I like to have trailer, thumbnail in the movie folders. The thumbs I use the thumbnail is a quick identification when finding the trailer files and the trailers allow a preview of the movie.

I download movie trailer and thumbnail files to a common folder because, I thought it'd be easy to use a RegExp test for locating and retrieving these files. I store these files using the name of the folder. Example: Citizen Kane (1941). The trailer is named "Citizen Kane (1941)-trailer.mp4". I also store a thumbnail files as "Citizen Kane (1941)-thumb.jpg" in the same folder.

Once identified, the sidecars are moved to the video folder.

I expected to do a regular expression test using the name of the video folder to find these sidecar files. I failed at that attempt. I had no idea why, so I added text file writes to show the values of my variables at each step. Ironically, it didn't help me to find a way to use a variable for the RegExp test, but it did help me to come up with a very fast alternative (using fileExists to look for the sidecars).

Here's what I came up with:

//		getSideCars.js
// Look for a matching trailer file from L:\WIP\sideCars
// folder, move it to video folder
// Search Name: (\(\d{4}\))$          Search type: Regular Expression
// Search Look in: L:\WIP\NTemp\

var tracer, strComparName, Script_Engine;
Script_Engine = ScriptEngine() + " v." + ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion() + "." + ScriptEngineBuildVersion();
var objFSO = new ActiveXObject( "Scripting.FileSystemObject" );
var debugFile = "getSideCars.0.bugs.txt"
var bugSpray = "L:\\WIP\\BugFiles\\" + debugFile;
var trailerDir = "L:\\WIP\\sideCars\\";
					
var regExThumb = new RegExp( "\-thumb\.jpg$", "i" );
var regExTrailer = new RegExp("\-trailer\.mp4$", "i");


	if (!objFSO.FileExists(bugSpray))
		objFSO.CreateTextFile(bugSpray, true);
	tracer = objFSO.OpenTextFile(bugSpray, 2);
		tracer.WriteLine("		  TinyTest.js");
		tracer.WriteLine();
		tracer.WriteLine("		--- Globals ---");
		tracer.WriteLine();
		tracer.WriteLine("Scripting engine: " + Script_Engine);
		tracer.WriteLine("Opened text file: " + debugFile);
		tracer.WriteLine("Search Parameter: " + SearchParms.Filename);
		tracer.WriteLine("Search location: " + SearchParms.LookIn);
		tracer.WriteLine("Search location exists: " + objFSO.FolderExists(SearchParms.LookIn));
		tracer.WriteLine("Trailer dir name: " + trailerDir);
		tracer.WriteLine("Trailer dir exists: " + objFSO.FolderExists(trailerDir));
		tracer.WriteLine("Tracer file name: " + bugSpray);
		tracer.WriteLine("Tracer file exists: " + objFSO.FileExists(bugSpray));
		tracer.WriteLine("Current process File name: " + SearchParms.CurrentFilename);
		tracer.WriteLine("Current process File fldr: " + SearchParms.CurrentFilePath);
		tracer.WriteLine();
	tracer.close();
	
function isValidFileName( strPath, strFileName )
{
    $1 = strFileName;
    var strCopyTo = strPath;
    var bIsValid = true;
    var bHasThumb = false;
    var bHasTrailer = false;
	var strTrailer  = "\-trailer\.mp4";
	var strVidDirPath = strPath + strFileName + "\\";
//	var strVidDirPath = objFSO.GetAbsolutePathName(strPath) + "\\";   //This callout has the same result as the one above;
	
	tracer = objFSO.OpenTextFile(bugSpray, 8);
		tracer.WriteLine("-----------------------------------------------------------------");
		tracer.WriteLine();
		tracer.WriteLine("			--- Locals ---");
		tracer.WriteLine();
		tracer.WriteLine("	Video full path (strVidDirPath): " + strVidDirPath);
		tracer.WriteLine("	Video full path exists: " + objFSO.FolderExists(strVidDirPath));
		tracer.WriteLine("	Video dir path (strPath): " + strPath);
		tracer.WriteLine("	Video dir path exists: " + objFSO.FolderExists(strPath));
		tracer.WriteLine("	Video dir name (strFileName): " + strFileName);
		tracer.WriteLine("	Video dir name exists: " + objFSO.FolderExists(strFileName));
		tracer.WriteLine("	bHasTrailer = " + bHasTrailer);
		tracer.WriteLine();
		tracer.WriteLine();
		tracer.WriteLine("			--- Comparisons ---");
		tracer.WriteLine();
	tracer.close();

	try
    {	
       	if ( objFSO.FolderExists( trailerDir ) )
        {
			var folderCheck = objFSO.GetFolder(trailerDir);
            var fc = new Enumerator(folderCheck.files);

            for (; !fc.atEnd(); fc.moveNext())
            {	
				if (!regExThumb.test(fc.item()))
				{
	            	strComparName = fc.item().Name.substr(0, fc.item().Name.length-strTrailer.length);
	            	tracer = objFSO.OpenTextFile(bugSpray, 8);
						tracer.WriteLine("        Video dir compare: " + "_" + strFileName + "_");
						tracer.WriteLine("        Trailer name: " + "_" + fc.item().name + "_");
						tracer.WriteLine("        Trailer base name: " + "_" + strComparName + "_");
					tracer.Close();
//					strCopyTo = strVidDirPath;
					if (strFileName == strComparName)
					{
						bHasTrailer = true; 
						fc.item().Copy(strCopyTo);	// found trailer, copy it to video folder
//						fc.item().Move(strCopyTo);	// found trailer, move it to video folder
		               	tracer = objFSO.OpenTextFile(bugSpray, 8);
							tracer.WriteLine("        Match found, copied to: " + strCopyTo);
							tracer.WriteLine();
						tracer.Close();
					return bIsValid && bHasTrailer;
					}
					else
					{
		               	tracer = objFSO.OpenTextFile(bugSpray, 8);
							tracer.WriteLine("                    --- No match found ---");
							tracer.WriteLine();
						tracer.Close();
					}
				}
            }
		}
     }

    catch( ErrCode )  
    {
        bIsValid = false;
    }
	   
    return bIsValid && bHasTrailer;
}

I open the debug file initially, before the function call and write values that will only show up in the beginning of the text file, rather repeating this information for each search. Obviously, you can only check values that are setup before the function call. Using this method allowed me to dial in my code for the fastest iteration.

These writes take up a lot of space and slow the script down, so they need to be removed after the script behaves the way you want it too. By contrast, here is the code without all the file writes:

//		getSideCars.js
// Look for a matching trailer file from L:\WIP\sideCars
// folder, move it to video folder
// Search Name: (\(\d{4}\))$          Search type: Regular Expression
// Search Look in: L:\WIP\Ntemp\


var thumbCount = 0, 
	trailerCount = 0;

var objFSO = new ActiveXObject( "Scripting.FileSystemObject" );
var sideCarsDir = "L:\\WIP\\Trailers\\";
	
if (objFSO.FolderExists(sideCarsDir))
	var sideCars = objFSO.GetFolder(sideCarsDir);
					
function isValidFileName( strPath, strFileName )
{
    var bIsValid = true;
	var	bGetThumb = false
    var bGetTrailer = false;
	var	bVidDirThumb = false
    var bVidDirTrailer = false;
    var trailerExt = "\.mp4";
	var thumbName = strFileName + "\-thumb\.jpg";
	var trailerName = strFileName + "\-trailer";
	var strVidDir = strPath + strFileName;
	var thumbFull = sideCars + "\\" + thumbName;
    var trailerFull = sideCars + "\\";
    var strMoveTo = strVidDir + "\\";
    var copyThumb, copyTrailer;
	
	
	if (objFSO.FileExists(strMoveTo + trailerName + "\.mkv")) 
		bVidDirTrailer = true;
	if (objFSO.FileExists(strMoveTo + trailerName + trailerExt))
		bVidDirTrailer = true;
	 
	if (objFSO.FileExists(strMoveTo + thumbName))
		bVidDirThumb = true;

	if (bVidDirTrailer && bVidDirThumb)
		return !bIsValid;		
	
	
	if (objFSO.FileExists(trailerFull + trailerName + "\.mkv"))
		trailerExt = "\.mkv";
	trailerName = trailerName + trailerExt;	
	trailerFull = trailerFull + trailerName;

	if (!bVidDirTrailer)
	{
		bGetTrailer = objFSO.FileExists(trailerFull);
		if (bGetTrailer) 
		{
			copyTrailer = objFSO.GetFile(trailerFull);
			copyTrailer.Move(strMoveTo);	// found trailer, move it to video folder
		}
	}	
	if (!bVidDirThumb)
	{
		bGetThumb = objFSO.FileExists(thumbFull);
		if (bGetThumb) 
		{
			copyThumb = objFSO.GetFile(thumbFull);
			copyThumb.Move(strMoveTo);	// found trailer, move it to video folder
		}	
	}	
	
    return bIsValid && (bGetTrailer || bGetThumb);
}

Maybe someone else will find this useful, so, take what you like and use it as your own.

Have a good day, FLP community.
Mike

by (225 points)
...