Skip to main content
November 17, 2013
Question

Renaming a file you already have in file obejct?

  • November 17, 2013
  • 0 replies
  • 335 views

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.

This topic has been closed for replies.