3 Replies Latest reply on Oct 29, 2013 9:23 AM by Michael L Hale

    Getting javascript to ignore a specific file type

    Ninetails

      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[i].name;

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

         {

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

            {

              renderTypes.push(fileList[i].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?

        • 1. Re: Getting javascript to ignore a specific file type
          Michael L Hale Level 5

          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);
          
          • 2. Re: Getting javascript to ignore a specific file type
            Ninetails Level 1

            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[i].name;

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

               {

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

                  {

                    renderTypes.push(fileList[i].name);

                  }

              }

              

            }

            • 3. Re: Getting javascript to ignore a specific file type
              Michael L Hale Level 5

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