6 Replies Latest reply on Feb 22, 2016 8:12 PM by SHJeon

    AIR copyTo(); issue

      Hey Guys,
      I'm having an issue with the copyTo() function. I get the following error when i try to copy a directory to either a root directory (like a flash drive F:\) or if i try to copy to a directory w/ subdirectories (C:\Program Files\).

      “Error #3012: Cannot delete file or directory.”

      I get this w/ overwrite set to both true and false.

      Is there any fix for this?

        • 1. Re: AIR copyTo(); issue
          JayStang Level 1
          • 2. Re: AIR copyTo(); issue
            flexstone Level 1
            I would suspect that this is a security restriction -

            I would not be surprised if you could only WRITE to application storage, my documents, or the desktop.....

            * File.applicationStorageDirectory —a storage directory unique to each installed AIR application
            * File.applicationDirectory —the read-only directory where the application is installed (along with any installed assets)
            * File.desktopDirectory —the user's desktop directory
            * File.documentsDirectory —the user's documents directory
            * File.userDirectory —the user directory
            • 3. Re: AIR copyTo(); issue
              Jed Schneider Level 1
              does it work to copy the file to you your desktop, or documents directory? If yes, but not to C:\Program Files, it is probably because you (actually the flex app) are not authorized as an administrator on your machine, and thus do not have write access above your user directory. you'd have to change permissions on the device. if you are looking to save out a file or something, try using the File.browseForDirectory method to identify a path.
              • 4. Re: AIR copyTo(); issue
                JayStang Level 1
                Well it didn't seem like it was a security error. I wasn't able to copy to C:\Program Files\, but i was able to copy to C:\Program Files\test\. However... if i add any other files or directories to the "test" directory. Pretty much i've come to the conclusion that the copyTo() function does not work on directories that are not empty.

                I was using the browseToDirectory() method to have the user select where they wanted to copy to. My solution is just just always create a subdirectory to whereever they've selected so i know it's a new directory w/ no other files for folders in it.

                Still doesn't make sence to me but i can't waste anymore time on this. Thanks for the help guys!
                • 5. Re: AIR copyTo(); issue

                  This is because your destination folder is read-only.

                  • 6. Re: AIR copyTo(); issue

                    It is because copyTo is copying file(or folder) to exact where it pointing to.

                    This concept might be confusing.

                    The point is  "copyTo" is literally copyTo where the File destination pointing to. IT IS NOT "copyInto".

                    So, if you try to copy a folder to folder,  target_folder is being asked 'replaced' into source folder's name.

                    If target_folder is in use (of course it is IN USE by current process, so can't be replaced), you will have the error msg.


                    So, it is recommended you make more explicit target destination, such as,

                    source_folder.copyTo (temp_folder.resolvePath(source_folder.name));  OR
                    source_folder.copyTo (temp_folder.resolvePath(source_file.name));