4 Replies Latest reply on Sep 14, 2016 3:39 AM by Whatevermajorloser

    Quicker way to get files than getFiles()?

    Whatevermajorloser Level 1

      I've written a script that searches a shared network drive for files containing a 6 digit number, that the user enters, using getFiles() with a filter. It then pushes those files into a listbox and presents the user with some file management options relevant to the work we do. While it works fine, it is however very slow.

       

      We have another, standalone app written in AppleScript that we use purely as a tool for searching and opening files on said drive. While it's extremely fast in finding files, the person that made it unfortunately left a while ago and we'd like to have a replacement with some more options. I remember him mentioning that it uses grep and I think it does so somehow in the command line (I'm not sure, still quite new to programming and when he told me at the time I hadn't even started learning), which is why it's so fast.

       

      I wonder if I can employ something similar, or is getFiles() my only option within the Photoshop framework?

        • 1. Re: Quicker way to get files than getFiles()?
          Pedro Cortez Marques Level 3

          Hi

           

          Unfortunatly getFiles is slow indeed.

          The only chance to minimize what you want using photoshop framework is to use it the less possible you can to retrieve what you need.

           

          If you are using photoshop framework and you are not able to find a applescript connection to it, I would suggest you use this:

           

          var sixDigitFiles = Folder([Folder to search]).getFiles( function(f) { return (f instanceof File && f.name.match(/\d{6}/) != null);});
          

           

          I do not know if it will reduce the time of retrieving your files, but at least you can try.

           

          Regarding applescript, I think it could be possible to send a request (folder) to it and retrieve the results as a XML that Photoshop framework could read.

          Photoshop framework is much faster reading xml content then getFiles()

          • 2. Re: Quicker way to get files than getFiles()?
            Whatevermajorloser Level 1

            Hi Pedro, thanks for the reply. I will definitely try your suggestion when I'm back at work in a couple of days. This is what I'm currently using:

             

            var searchFolder = Folder('path/to/folder');
            var getFilesFilter = new RegExp("(?=" + SearchField.text + ")\\d{6}");
            var myFileArray = searchFolder.getFiles(getFilesFilter)
            

             

            Comparing it to mine, are you able to already tell if your method might be faster? If it is, do you mind quickly explaining why (still learning )?

             

            Thanks!

            • 3. Re: Quicker way to get files than getFiles()?
              Pedro Cortez Marques Level 3

              Hi,

               

              I have just tested the 2 ways on a bunch of 500 files and the results in miliseconds are pretty much identical.

              Still, it takes too long for rutine operations both ways.

               

              Another ways to get the code more understandable, you can use functions like this and use them as an argument.

              In this example, it verifies if it is a File (could be also a Folder) and if not, it doesn't verify the RegExp routine, avoiding that processing time.

              Example:

               

              var searchFolder = Folder('S:\\'); 
              var myFileArray = Folder(searchFolder).getFiles( file3digits ); 
              
              function file3digits (f) {
                  if (f instanceof File) {
                      if (f.name.match(/\d{6}/g) != null) return f;
                  }
              }
              

               

              Hope it helps.

              1 person found this helpful
              • 4. Re: Quicker way to get files than getFiles()?
                Whatevermajorloser Level 1

                Gotcha. Thanks, Pedro. Much appreciated!