2 Replies Latest reply on Jun 2, 2017 9:25 AM by pixxxel schubser

    Only open psd

    showshow Level 1

      Hello,

       

      How can i, when i use the script beyond, only opens ".psd files" ?

       

      Thanks a lot

       

      / Pops open a dialog for the user to
      // choose the folder of documents to process
      var inputFolder = Folder.selectDialog("Select a folder of documents to process");
      
      
      // Pops open a dialog for the user to
      // set the output folder
      
      
      
      
      // Open Folder of Images
      OpenFolder();
      
      
      // show the path to an output folder
      
      
      
      
      /////////////////////////
      // FUNCTIONS
      /////////////////////////
      
      
      // Given the a Folder of files, open them
      function OpenFolder() {
              var filesOpened = 0;
              var fileList = inputFolder.getFiles();
              for ( var i = 0; i < fileList.length; i++ ) {
                // Make sure all the files in the folder are compatible with PS
                      if ( fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese( fileList[i], gFilesToSkip )) {
                              open( fileList[i] );
                              filesOpened++;
                      
                      /////////////////////////
        // Put all your processing functions...
        /////////////////////////
      
                     
                     
        /////////////////////////
        // ...in the area between these two comments.
        /////////////////////////
      
        }
              }
              return filesOpened;
      }
      
      
      
      
      // given a file name and a list of extensions
      // determine if this file is in the list of extensions
      function IsFileOneOfThese( inFileName, inArrayOfFileExtensions ) {
        var lastDot = inFileName.toString().lastIndexOf( "." );
        if ( lastDot == -1 ) {
        return false;
        }
        var strLength = inFileName.toString().length;
        var extension = inFileName.toString().substr( lastDot + 1, strLength - lastDot );
        extension = extension.toLowerCase();
        for (var i = 0; i < inArrayOfFileExtensions.length; i++ ) {
        if ( extension == inArrayOfFileExtensions[i] ) {
        return true;
        }
        }
        return false;
      }
      
        • 1. Re: Only open psd
          Joachim Hiller Level 1

          You can try i

           

          File.prototype.fileExt = function () {

             return this.name.replace(/^.*\./, '');
          };

          var inputFolder = Folder.selectDialog("Please select the input folder");

          if (inputFolder != null) {

           

           

             var fileList = inputFolder.getFiles();
             for (var a in fileList) {

             if (fileList[a] instanceof File) {

             //check fileextension(,psd...)
             var fileExtension = fileList[a].fileExt();

             //only psd
             if (fileExtension === "psd") {

           

             //open Image
             open(fileList[a]);

             }

            }

            }

           

          }

          1 person found this helpful
          • 2. Re: Only open psd
            pixxxel schubser MVP & Adobe Community Professional

            Hi showshow,

            you can simple use a "file mask"

            var SourceFolder = new Folder('~/desktop/Testdateien'); // use the folder with your psd-files
            sourcePics = SourceFolder.getFiles(/\.psd$/i);
            alert(sourcePics.join("\n"));
            

             

            Have fun