Copy link to clipboard
Copied
Hello,
I am trying to write a script that does the following:
I know how to do 1 and 3, but have no idea how to do #2. I have used the following code to get all files, but can't differentiate mif files.
var myFolder = Folder.selectDialog ("Select a folder");
var files = myFolder.getFiles();
I would appreciate help figuring this out.
Thank you,
Joseph
var myFolder = Folder.selectDialog ("Select a folder");
var files = myFolder.getFiles("*.mif")
for (var i=0; i < files.length; i++)
{
var currentFile = files;
var fileSystemFileName = currentFile.fsName;
//to something with file object or file name
}
should work like this
Markus
Copy link to clipboard
Copied
Look for the JavaScript Tools Guide. This explains how to use the Folder and File objects.
Copy link to clipboard
Copied
I just realized that I could turn the filename into a string, then search the end of the string for "mif".
var myFolder = Folder.selectDialog ("Select a folder");
var allFiles = myFolder.getFiles();
var mifFiles = [];
for(var i = 0; i < allFiles.length; i++)
{
var str = allFiles + "";
if(str.substring(str.length - 3, str.length) == "mif")
{
mifFiles.push(allFiles);
}
}
Copy link to clipboard
Copied
var myFolder = Folder.selectDialog ("Select a folder");
var files = myFolder.getFiles("*.mif")
for (var i=0; i < files.length; i++)
{
var currentFile = files;
var fileSystemFileName = currentFile.fsName;
//to something with file object or file name
}
should work like this
Markus
Copy link to clipboard
Copied
Markus,
That works better than what I just came up with. Thank you!
Joseph