• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Loop through all .mif files in a given folder

New Here ,
Jul 18, 2019 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

TOPICS
Scripting

Views

1.9K

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
community guidelines

correct answers 1 Correct answer

Engaged , Jul 18, 2019 Jul 18, 2019

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

Votes

Translate

Translate
Advocate ,
Jul 18, 2019 Jul 18, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
New Here ,
Jul 18, 2019 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);

    }

}

Votes

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
community guidelines
Engaged ,
Jul 18, 2019 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

Votes

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
community guidelines
New Here ,
Jul 18, 2019 Jul 18, 2019

Copy link to clipboard

Copied

LATEST

Markus,

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

Joseph

Votes

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
community guidelines