4 Replies Latest reply on Dec 28, 2009 9:07 PM by Prateek Goyal

    Problem getting the relative path

    Prateek Goyal
      Hello,
      I have created an application which loads the content of a xml file into AIR application. It works perfectly if i supply the absoulete path but i dont know how to get the relative path of the xml file while executing the application.
      Please help.
      Regards,
      Prateek
        • 1. Re: Problem getting the relative path
          jshrek Level 1

          In JavaScript I do the following to read a text file from the application directory and then include in the html document... it is relative to the application directory, so regardless of the computer or location of install, it will always read the file:

           

            var _Filename = "includes/myHTML.txt";

            var _theFile = air.File.applicationDirectory.resolvePath(_Filename);
            var _theStream = new air.FileStream();
            _theStream.open(_theFile, air.FileMode.READ);
            var _theContents = _theStream.readUTFBytes(_theStream.bytesAvailable);
            document.write(_theContents); //
            _theStream.close();

           

           

          In place of applicationDirectory, you also have these options:

           

          applicationStorageDirectory—a storage directory unique to each installed AIR application

           

          applicationDirectory—the read-only directory where the application is installed (along with any installed assets)

           

          desktopDirectory—the user's desktop directory

           

          documentsDirectory—the user's documents directory

           

          userDirectory—the user directory

          1 person found this helpful
          • 2. Re: Problem getting the relative path
            Prateek Goyal Level 1

            Hey,

            Thanks for the reply but my problem is some what different.

            My directory structure is like:

            TestProject

                bin-debug

                config

                      config.xml

                libs

                src

             

            As you have suggested in the code "applicationDirectory" which returns the path of bin-debug.I need to read the config.xml which is present in config folder for which i need to give the relative path from the program which present in src folder. I have tried with /../config/config.xml to move a level up in the directory structure but it did'nt worked. It is throwing the error "Error #3003: File or directory does not exist"

             

             

             

             

            • 3. Re: Problem getting the relative path
              jshrek Level 1

              I haven't tried this at all, but where does applicationStorageDirectory take you?

               

              I don't know if you can customize where it points to or not.

               

              I suppose the only other solution I can think of is to move your config directory under the bin-debug directory.

               

              I am a very long way from being an expert at AIR, so there be other options I am not aware of.

               

              Hope that helps!

              • 4. Re: Problem getting the relative path
                Prateek Goyal Level 1

                Hey,

                I have also tried with application storage directory, but this is actually a unique storage path for every AIR application. This takes me to a

                "C:\Documents and Settings\user\Application Data\testProject\Local Store" which is unique space.

                Anyways thanks for the help.