Note that there are some explanatory texts on larger screens.

plurals
  1. PORenaming a file in as3 AIR - how to do it if you have file's native path in a var?
    primarykey
    data
    text
    <p>The following code is great for renaming a file if you know the file is in applicationStorageDirectory</p> <pre><code>var sourceFile:File = File.applicationStorageDirectory; sourceFile = sourceFile.resolvePath("Kalimba.snd"); var destination:File = File.applicationStorageDirectory; destination = destination.resolvePath("test.snd"); try { sourceFile.moveTo(destination, true); } catch (error:Error) { trace("Error:" + error.message); } </code></pre> <p>How do you set the sourceFile if all you have is the file's native path in a string? Like this:</p> <pre><code>D:\Software\files\testList.db </code></pre> <p>This throws errors:</p> <pre><code>sourceFile = sourceFile.resolvePath("D:\Software\files\testList.db"); </code></pre> <p>The idea is I want to rename a file I had previously loaded into a var. I figured I'd extract the native path to a String var, null the File var (so the OS doesn't tell me it can't be renamed while the file is opened in flash), resolve that nativePath as the sourceFile, and use moveTo to rename the file on the hard drive.</p> <p>Cheers for taking a look.</p> <p>EDIT:</p> <p>I've set up a test AIR app with only the following in it:</p> <pre><code>import flash.events.*; import flash.filesystem.*; var original = File.documentsDirectory; original = original.resolvePath("D:\\Software\\test\\October.db"); var destination:File = File.documentsDirectory; destination = destination.resolvePath("copy.db"); original.addEventListener(Event.COMPLETE, fileMoveCompleteHandler); original.addEventListener(IOErrorEvent.IO_ERROR, fileMoveIOErrorEventHandler); original.moveToAsync(destination); function fileMoveCompleteHandler(event:Event):void { trace(event.target); // [object File] } function fileMoveIOErrorEventHandler(event:IOErrorEvent):void { trace("I/O Error."); } </code></pre> <p>This fails, as does using D:\Software\test\October.db</p> <p>I guess what I want to know it - how do you do the resolvePath thing if you already know the full path? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload