1 Reply Latest reply on Mar 21, 2011 4:30 AM by samschauhan

    File problem

    Ladislav Navrátil Level 1

      Hi all,

       

      i would like to ask for some informations about works with files.

       

      User of my application should select files from his computer(probably by file.browseForOpenMultiple), than i would like to copy selected files toapplicationStorageDirectory.

       

      But when i am trying do that by:

       

      var file:File = new File();

      file.addEventListener(FileListEvent.SELECT_MULTIPLE, onSelected);

      file.browseForOpenMultiple("something");

       

      function onSelected(event:FileListEvent):void{

           var destinationFile:File = File.applicationStorageDirectory;

           for(var i:Number = 0; i < event.files.length; i++){

                event.files[i].copyTo(destinationFile);

           }

       

      }

       

      it doesnt works.

       

      after running previously code, flash builder made an error:

       

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

      at flash.filesystem::File/copyTo()

       

      Thanks for your help.

        • 1. Re: File problem
          samschauhan Level 1

          Hi,

           

          The code you have shared will work when you want to copy a directory.

           

          For copying a file you have to make sure that destinationFile is a file.

           

          This works:

           

                    function onSelected(event:FileListEvent):void
                      {
                          var destinationFile:File=File.applicationStorageDirectory.resolvePath("test.txt");

           

                          for (var i:Number=0; i < event.files.length; i++)
                          {

           

                              event.files[i].copyTo(destinationFile,true);

           

                          }

           

                      }

           

          Regards,

          SAM