File.applicationDirectory.resolvePath – Can’t get to the relative parent

I was banging my head against a wall trying to do this in a unit test:
var file : File = File.applicationDirectory.resolvePath(“./../src/test/SomeFile.txt”);

Turns out that you can’t get to the relative parent of the applicationDirectory though. Flex/AIR has abstracted that away from you, presumably to prevent you from looking in places you shouldn’t. (Edit: I no longer believe that, as you can easily get to any arbitrary folder you want via the File constructor.) So, I just told the project to copy non-embedded assets to the output folder, and now as long as the files for my tests are located somewhere in one of my source folders, I can reference the test files I want relative to the applicationDirectory.

UPDATE: Thanks to Jijith chandran for making the following suggestion and spelling out how to use the File constructor:
You can get it using the following
[code lang="as3"]

new File(File.applicationDirectory.nativePath).resolvePath(”./../src/test/SomeFile.txt”);

[/code]

4 Responses to “File.applicationDirectory.resolvePath – Can’t get to the relative parent”

  1. Jijith chandran April 12, 2011 at 8:50 pm #

    You can get it using the following
    new File(File.applicationDirectory.nativePath).resolvePath(”./../src/test/SomeFile.txt”);

    • prasad vejju July 28, 2011 at 12:46 am #

      Hi Jijith,
      Thanks a lot for posting this solution.I really got struck here and managed the generated pdf from app storage directory.But the solution of u make me to move with my actual application requirement.

      Bye

  2. Josh Knopp June 10, 2011 at 1:46 pm #

    Thanks for posting a solution to this, it was driving me nuts!

  3. Kevin January 29, 2013 at 2:10 am #

    Ah, count me as another satisfied customer :)

    This was driving me crazy, too.

Leave a Reply