Quantcast
Channel: Adobe Community : All Content - AIR Development
Viewing all articles
Browse latest Browse all 2954

Renaming a file you already have in file obejct?

$
0
0

Hi

 

I have a file I've already loaded into a var.

 

I've made a function that I want to rename the file on the hard drive using moveTo(), so that backup_ is added to the front of the file name:

 

 

myFile.nativePath;

 

 

renameMyFile(myFile);

 

public function renameMyFile(filePath:String)

        {

            var original = File.documentsDirectory;

            original = original.resolvePath(filePath);

           

            var destination:File = File.documentsDirectory;

            destination =  destination.resolvePath("backup_"+filePath);

 

         

          original.addEventListener(Event.COMPLETE, fileMoveCompleteHandler);

            original.addEventListener(IOErrorEvent.IO_ERROR, fileMoveIOErrorEventHandler);

            original.moveToAsync(destination);

 

        }

 

 

private function fileMoveCompleteHandler(event:Event):void {

                trace(event.target); // [object File]

            }

 

private function fileMoveIOErrorEventHandler(event:IOErrorEvent):void {

               

                trace("I/O Error."); 

            }

 

 

It keeps tracing "I/O Error."  The new file doesn't already exist, so the error isn't thrown due to it already being there.

 

What is the correct way to do this, if you already have the file's nativePath in a string?

 

Thanks guys.


Viewing all articles
Browse latest Browse all 2954

Trending Articles