4 Replies Latest reply on Nov 7, 2013 5:30 AM by BEGINNER_X

    Copy and Paste in selected folder

    BEGINNER_X Level 3

      Hi All,

       

      I need to select(copy) ".pdf" files and paste into selected folder.

       

      Using Mac.

       

      var file = File.openDialog("Please choose PDF", "PDF:*.pdf");

       

      var destinationFolder = Folder.selectDialog("Select Paste Folder");

       

       

      Could anyone help on this.

       

      Thanks in advance

      Beginner_X

        • 1. Re: Copy and Paste in selected folder
          Sajeev Sridharan Level 4

          Try this, (tested in windows not Mac)

           

           

          var file = File.openDialog("Please choose PDF", "PDF:*.pdf");

          var destinationFolder = Folder.selectDialog("Select Paste Folder");

          var target = File(destinationFolder + "/" + file.name);

          file.copy(target);

           

           

          Vandy

          • 2. Re: Copy and Paste in selected folder
            BEGINNER_X Level 3

            Hi vandy,

             

            Thanks for your response. Its works like a charm...

             

            I tuned the above coding for copy folder and paste in the selected folder.

             

            But it should be fail.

             

             

            var file = Folder.selectDialog("Select Copy Folder");
            
            var destinationFolder = Folder.selectDialog("Select Paste Folder");
            
            var target = File(destinationFolder + "/" + file.name);
            
            file.copy(target);
            
            

            Could you please help for the request.

             

            Thanks in advance

            Beginner_X

            • 3. Re: Copy and Paste in selected folder
              Sajeev Sridharan Level 4

              May be something like this, I haven't tested it

               

              var file = Folder.selectDialog("Select Copy Folder");  

              var destinationFolder = Folder.selectDialog("Select Paste Folder");  

              file.copy(destinationFolder);

               

              Vandy

              • 4. Re: Copy and Paste in selected folder
                BEGINNER_X Level 3

                Hi Vandy,

                 

                Thanks for your response...

                 

                Above  coding is not worked out for moving folders...

                 

                But using forum I got below function, it works great

                 

                function copyFolder(sourceFolder, destinationFolder) {
                    var sourceChildrenArr = sourceFolder.getFiles();
                    for (var i = 0; i < sourceChildrenArr.length; i++) {
                        var sourceChild = sourceChildrenArr[i];
                        var destinationChildStr = destinationFolder.fsName + "/" + sourceChild.name;
                        if (sourceChild instanceof File) {
                            copyFile(sourceChild, new File(destinationChildStr));
                        }
                        else {
                            copyFolder(sourceChild, new Folder(destinationChildStr));
                        }
                    }
                }
                
                
                function copyFile(sourceFile, destinationFile) {
                    createFolder(destinationFile.parent);
                    sourceFile.copy(destinationFile);
                }
                
                
                function createFolder(folder) {
                    if (folder.parent !== null && !folder.parent.exists) {
                        createFolder(folder.parent);
                    }
                    folder.create();
                }
                

                 

                Any other coding is also appreciatable....

                 

                Thanks in advance

                Beginner_X