Highlighted

Loop through all .mif files in a given folder

New Here ,
Jul 18, 2019

Copy link to clipboard

Copied

Hello,

I am trying to write a script that does the following:

  1. Asks the user for a folder path.
  2. Loops through all of the .mif files in this folder.
  3. Opens, modifies, and saves each file.

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

TOPICS
Scripting

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Loop through all .mif files in a given folder

New Here ,
Jul 18, 2019

Copy link to clipboard

Copied

Hello,

I am trying to write a script that does the following:

  1. Asks the user for a folder path.
  2. Loops through all of the .mif files in this folder.
  3. Opens, modifies, and saves each file.

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

TOPICS
Scripting

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 18, 2019 0
Advocate ,
Jul 18, 2019

Copy link to clipboard

Copied

Look for the JavaScript Tools Guide. This explains how to use the Folder and File objects.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 18, 2019 0
New Here ,
Jul 18, 2019

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);

    }

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 18, 2019 0
Engaged ,
Jul 18, 2019

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 18, 2019 0
New Here ,
Jul 18, 2019

Copy link to clipboard

Copied

Markus,

That works better than what I just came up with. Thank you!

Joseph

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 18, 2019 0