2 Replies Latest reply on Jun 28, 2013 10:23 PM by shilpa25

    remove file extension in a folder.

    shilpa25 Level 1

      HI Forum,

       

      I have a strange request to you..

       

      I have a list of files (xxxxx.jpg) in a folder XYZ in desktop.

       

      I want to remove .jpg extension and leave the file name as it is.

       

      Is this possible.

       

      something i got after googling....but no worth.....

       

      imglist = File(Folder("C:\\Documents and Settings\\Variables\\Desktop\\XYZ").getFiles);

                     imglist.replace(/(.*)\.[^.]+$/, "$1");

       

      thanks,...

      shil

        • 1. Re: remove file extension in a folder.
          dln385

          Your description is unclear.

           

          If you want to rename the files on your hard drive, make a backup of your folder and then use this code:

          var myFiles = (new Folder("C:/Documents and Settings/Variables/Desktop/XYZ")).getFiles();
          for (var i = 0; i < myFiles.length; i++) {
              var myFile = myFiles[i];
              if (myFile instanceof File) {
                  var myFileName = myFile.displayName;
                  myFile.rename(myFileName.slice(0, myFileName.lastIndexOf(".")));
              }
          }
          

           

          If you want an array of file names without extensions, use this code:

          myFolder = new Folder("C:/Documents and Settings/Variables/Desktop/XYZ");
          var myFiles = myFolder.getFiles(function(file) {return myFile instanceof File;});
          for (var i = 0; i < myFiles.length; i++) {
              var myFileName = myFiles[i].displayName;
              myFiles[i] = myFileName.slice(0, myFileName.lastIndexOf("."));
          }
          alert(myFiles.toString());
          
          • 2. Re: remove file extension in a folder.
            shilpa25 Level 1

            Bingo!

             

            dln385, fantastic!!!.

             

            excellent explanation. The first approach is good to go with.

             

            I just have a other question. If i'm not using extendScript tool kit,  on which paltform this code can be executed.

             

            Because I used to live with extendscript tool kit. I just want to share this code to other user who don't have adobi software installed.

             

            many thanks sir!...