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

Getting javascript to ignore a specific file type

Guest
Oct 29, 2013 Oct 29, 2013

Copy link to clipboard

Copied

I've created a Javascript file that allows the user to search for a specific folder on their workstation and loads in all of the images contained with in that folder. Once they have selected the folder they want, a window appears and lets them select the file extentions they want to import. If there are no files in the folder, then the window gets populated.

However, the target folder also contains a single file extension I wish to be ignored (deleteing isn't an option) and I believe I have cracked the way for Javascript to ignore this file extenstion. This is what I have so far:

var filename = fileList.name;

   if (filename.match(/\.(stitchinfo)$/i) == null)

   {

      if(fileList.name.substring(0,beautyRender.length) === beautyRender)

      {

        renderTypes.push(fileList.name);

      }

   }

   

However, when I run the script with the above code, the script ignores all of the files contained in the folder. However, if I take out the file I want ignored, the images appear as they should in the selection window. I put it back in, nothing appears.

Can anyone see what it is I'm doing wrong?

TOPICS
Actions and scripting

Views

1.2K

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

Guru , Oct 29, 2013 Oct 29, 2013

The desktop in the code I posted was just an example. Add that function to your code and use it to filter out that extension. That way you don't have to worry about it later - those tiles are never part of the fileList array.

var fileList = samplesFolder.getFiles(ignoreMe);

Votes

Translate

Translate
Adobe
Guru ,
Oct 29, 2013 Oct 29, 2013

Copy link to clipboard

Copied

I think the best way to ignore an extension is to pass getFiles a custom function. What extension do you want to ignore? ".stitchinfo"?

function ignoreMe( f ){

   return f.name.match(/\.(stitchinfo)$/i) == null;

}

Folder("~/desktop").getFiles(ignoreMe);

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
Guest
Oct 29, 2013 Oct 29, 2013

Copy link to clipboard

Copied

Yes, stickinfo is the file extension I want ignored.

However, the folder that the user is targetting can be anywhere and the files need to be loaded dynamically and could potentially be anything. The only thing I know is that the folder could contain a stickinfo file and, if it does, it should ignore that and only deal with the other file types in the folder.

My full code for getting the user to select the folder and check what is in it as follows:

Prompt for folder location

var Path = Folder.selectDialog("Select Folder Location for Renders")

// Use the path to the application and append the samples folder

var samplesFolder = Folder(Path)

//Get the files

var fileList = samplesFolder.getFiles()

//Creat Array to hold names

var renderTypes = new Array();

//Parse Initial name to get similar render elements

var beautyRender = fileList[0].name

beautyRender = beautyRender.substr(0, beautyRender.length-4)

//Get the render elements with a similar name

for (var i = 0; i < fileList.length; i++)

{

var filename = fileList.name;

   if (filename.match(/\.(stitchinfo)$/i) == null)

   {

      if(fileList.name.substring(0,beautyRender.length) === beautyRender)

      {

        renderTypes.push(fileList.name);

      }

  }

  

}

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
Guru ,
Oct 29, 2013 Oct 29, 2013

Copy link to clipboard

Copied

LATEST

The desktop in the code I posted was just an example. Add that function to your code and use it to filter out that extension. That way you don't have to worry about it later - those tiles are never part of the fileList array.

var fileList = samplesFolder.getFiles(ignoreMe);

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