11 Replies Latest reply on Sep 18, 2012 9:11 PM by Trevorׅ

    Copy Files to another location without Changing DateModified using Javascript

    Velprakash Level 1

      Hi Expert,

               I've a issue while copying a file from one location to some other location. If I copied and paste manually, the Date modified is shown as same as copied file. But If I did it with JS codes, It's showing today's date for all(created, modified,accessed). I want the same as the copied file.  I worked out this in Java. But I need to did this only by using Javascript. Can anyone help me.......

       

      My codes is:

       

      File("C:\\Users\\Indesign\\Desktop\\New folder (2)\\abc\\1.jsx").copy("C:\\Users\\Indesign\\Desktop\\New folder (2)\\xyz\\1.jsx")

       

      Thanks and Regards,

      Vel.

        • 1. Re: Copy Files to another location without Changing DateModified using Javascript
          Trevorׅ Adobe Community Professional

          Hi Vel

           

          See http://forums.adobe.com/message/4671706#4671706 for a  recent discusion on it.

          You can't do it in JS but you can use doscript to call on AS and VB to do it.

          Seems to have the answer.In particular look at Kasyan Servetsky's script.

           

          Vel it's an idea to do a search before you ask the questions if you would of typed in "copy" the above post would of come up first.

           

          Regards,

           

          Trevor

          1 person found this helpful
          • 2. Re: Copy Files to another location without Changing DateModified using Javascript
            Velprakash Level 1

            Hi Trevor,

                  I thank you for your kind reply. But It's designed for Mac na... I'm using windows 7...

             

            Thanks and Regards,

            Vel.

            • 3. Re: Copy Files to another location without Changing DateModified using Javascript
              Trevorׅ Adobe Community Professional

              It's design for both Mac and Windows

              See my annotation (Kasyan's script).

               

              function MoveFile(myFile, myFolder) {
                  if (!myFile instanceof File || !myFolder instanceof Folder || !myFile.exists || !myFolder.exists) return false;
                  var myMovedFile = new File(myFolder.absoluteURI + "/" + myFile.name);
              
              //***************************************************************************************************************************************  
              // THIS IS THE WINDOWS BIT
              //************************************
              
                if (File.fs == "Windows")  {
                      var myVbScript = 'Set fs = CreateObject("Scripting.FileSystemObject")\r';
                      myVbScript +=  'fs.MoveFile "' + myFile.fsName + '", "' + myFolder.fsName + '\\"';
                      app.doScript(myVbScript, ScriptLanguage.visualBasic);
              
              //***************************************************************************************************************************************
              
              // NOW STARTS THE MAC BIT
              
                  }
                  else if (File.fs == "Macintosh") {
                      if (myFolder.fsName.match("Desktop") != null) {
                          var myMacFolder = myFolder.fsName.replace(/\//g, ":");
                          var myMacFile = myFile.fsName.replace(/\//g, ":");
                          var myAppleScript = 'tell application "Finder"\r';
                          myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';
                          myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';
                          myAppleScript += 'tell myFile\r';
                          myAppleScript += 'move to myFolder\r';
                          myAppleScript += 'end tell\r';
                          myAppleScript += 'end tell\r';
                      }
                      else if (myFolder.fsName.match("Documents") != null) {
                          var myMacFolder = myFolder.fsName.replace(/\//g, ":");
                          var myMacFile = myFile.fsName.replace(/\//g, ":");
                          var myAppleScript = 'tell application "Finder"\r';
                          myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';
                          myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';
                          myAppleScript += 'tell myFile\r';
                          myAppleScript += 'move to myFolder\r';
                          myAppleScript += 'end tell\r';
                          myAppleScript += 'end tell\r';
                      }
                      else {
                          var myMacFolder = myFolder.fullName.replace(/\//, "").replace(/\//g, ":");        
                          var myMacFile = myFile.fullName.replace(/\//, "").replace(/\//g, ":");
                          var myAppleScript = 'tell application "Finder"\r';
                          myAppleScript += 'set myFolder to folder "' + myMacFolder + '"\r';
                          myAppleScript += 'set myFile to document file "' + myMacFile + '"\r';
                          myAppleScript += 'tell myFile\r';
                          myAppleScript += 'move to myFolder\r';
                          myAppleScript += 'end tell\r';
                          myAppleScript += 'end tell\r';
                      }
                      app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);
                  }
                  if (myMovedFile.exists) {
                      return true;
                  }
                  else {
                      return false;
                  }
              }
              

               

              Going out now so don't expect any quick reply

               

              Trevor

              1 person found this helpful
              • 4. Re: Copy Files to another location without Changing DateModified using Javascript
                Velprakash Level 1

                Thanks again for your kind reply...

                 

                I used the script and it shows an error whilr running.

                It shows,

                error.jpg

                 

                then I go through google for this error and go through the below link.

                 

                http://helpx.adobe.com/legacy/kb/javascript-doscript-commands-fail-initiate.html

                 

                It's for CS4 & I'm having CS5.

                 

                But I'm using CS5. I can't find the specified Data key 838F........... in registry. Can u guide me...

                 

                Thanks and Regards,

                Vel.

                • 5. Re: Copy Files to another location without Changing DateModified using Javascript
                  Trevorׅ Adobe Community Professional

                  Sorry Vel,

                   

                  I don't have time to look into things now I suggest you ask Kasayan on the link I gave at the top.

                   

                  Trevor

                  • 6. Re: Copy Files to another location without Changing DateModified using Javascript
                    -hans- Level 4

                    Hi,

                     

                    seems like the Bridge copies files without changing modification date.

                     

                    #target Bridge

                     

                    var thumbnail = new Thumbnail(File.openDialog());

                    var target = new Thumbnail(Folder.selectDialog());

                    thumbnail.copyTo(target)

                     

                    Painfully, it has to be launched to use ... ;-)

                    1 person found this helpful
                    • 7. Re: Copy Files to another location without Changing DateModified using Javascript
                      Velprakash Level 1

                      Hi Mr. Hans,

                             Really Great.... Thanks a lot for your kind help............ It works fine..............

                       

                      Thanks again.

                       

                      With Regards,

                      Vel.

                      • 8. Re: Copy Files to another location without Changing DateModified using Javascript
                        Kasyan Servetsky Level 5

                        I'm sorry for the late reply, couldn't get down to this earlier.

                        Here's an example:

                         

                        Main();
                        
                        function Main() {
                            if (File.fs == "Windows")  {
                                var file = new File("/E/Temp_1/Test.txt");
                                var destinationFolderPath = "/D/Temp_2/";
                                var destinationFolder = new Folder(destinationFolderPath);
                                if (!destinationFolder.exists) destinationFolder.create();
                        
                                var vbScript = 'Set fs = CreateObject("Scripting.FileSystemObject")\r';
                                vbScript +=  'fs.CopyFile "' + file.fsName.replace("\\", "\\\\") + '", "' + destinationFolder.fsName.replace("\\", "\\\\") + "\\" + file.name + '"';
                        
                                app.doScript(vbScript, ScriptLanguage.visualBasic);
                            }
                        }
                        
                        • 9. Re: Copy Files to another location without Changing DateModified using Javascript
                          Velprakash Level 1

                          Thanks Kasyan...

                           

                          Thak u for ur kind reply.

                           

                          It's working fine in CS5.5. But in CS5, If i run this, it shows error, "Unable to load Adobe Indesign CS5 Type Library (Version 1.0)".

                           

                          The error color showed in the below line.

                           

                          app.doScript(vbScript, ScriptLanguage.visualBasic);


                          With Regards,

                          Vel.

                          • 10. Re: Copy Files to another location without Changing DateModified using Javascript
                            Kasyan Servetsky Level 5

                            I just tested it in CS5, Windows 7 and it works for me without any errors.

                            • 11. Re: Copy Files to another location without Changing DateModified using Javascript
                              Trevorׅ Adobe Community Professional

                              Hi Vel,

                               

                              Try replacing

                              app.doScript(vbScript, ScriptLanguage.visualBasic)
                              

                               

                              with

                              app.doScript(vbScript, ScriptLanguage.UNKNOWN, undefined, UndoModes.ENTIRE_SCRIPT, "Kasyans Copy");
                              

                               

                              Shouldn't make a difference but worth giving a go.

                               

                              Regards

                               

                              Trevor