2 Replies Latest reply: Mar 29, 2013 1:58 PM by Damon Edwards RSS

    File.copyTo(desktop, true) wiped my desktop

    Damon Edwards Community Member

      This is probably karma. I was making a little prank program for April fools for our office and it went horribly wrong. While testing some file operations, I was copying a file from the user directory to the desktop. The file did not already exist on the desktop, but I set the overwrite argument to true. Like so

       

      var userDirectory = File.userDirectory;

      var desktopDirectory = File.desktopDirectory;

      var fileToCopy = userDirectory.resolvePath('file.ext');

      fileToCopy.copyTo(desktopDirectory, true);

       

      So I run a Test->Publish so it's running in ADL - I go to look at my desktop and everything is gone. Completely gone. Yikes! Is this a bug? Is there anyway to recover my desktop? I'm on a Macbook Pro running OSX 10.8.3, Flash Pro CS6 with publish target AIR 3.4 for Desktop

        • 1. Re: File.copyTo(desktop, true) wiped my desktop
          chris.campbell Employee Hosts

          Unfortunately I think you specified the desktop directory as the file object to overwrite in the copyTo method.  See the red text in the docs below.

           

          newLocation The target location of the new file. Note that this File object specifies the resulting (copied) file or directory, not the path to the containing directory.


          Instead, I think what you wanted to write was:

           

          var userDirectory = File.userDirectory;

          var desktopDirectory = File.desktopDirectory;

          var fileToCopy = userDirectory.resolvePath('file.ext');

          var destinationFile:File = desktopDirectory.resolvePath("file.ext");

          fileToCopy.copyTo(destinationFile, true);

           

          It does seem to me like a file shouldn't be able to overwrite a folder.  This is the behavior on Windows.  I'd recommend opening a new bug on that over at bugbase.adobe.com.  Sorry you had to go through this, I unfortunately don't know of a way to revert this on the Mac.
          • 2. Re: File.copyTo(desktop, true) wiped my desktop
            Damon Edwards Community Member

            Well that's what I get for not reading the docs. Thanks Chris, I'll file the bug.