4 Replies Latest reply on Mar 29, 2010 9:11 AM by Loic.Aigon

    Is a File writable ?

    Loic.Aigon Adobe Community Professional

      Hi,

       

      I want to write a File on a local machine. I would like to check that the file is not open yet.

      Is that possible ?

       

      TIA Loic

        • 1. Re: Is a File writable ?
          rkewlani Level 2

          You might want to put the file.opene call in a try/catch block & take corrective actions in the catch block.

           

          try{

           

          file.open(...)

          ...

          ....

          }

          catch(e:Error)

          {

          ...

          ...

          ...

          }

          • 2. Re: Is a File writable ?
            Loic.Aigon Adobe Community Professional

            Hi,

             

            Thanks a lot for your answer.

             

            File.open() seems to return true whatever the context :-S (File open or not).

             

            The file is a PDF open in Acrobat BTW.

             

            Thanks again anyway.

             

            Loic

            • 3. Re: Is a File writable ?
              rkewlani Level 2

              I tried the piece of code given below & it worked for me. Even if the file is not opened, it doesn't make any chages to it (confirmed the checksum & it's the same)

               

              var file:File = File.desktopDirectory.resolvePath("123.pdf");
              var fileStream:FileStream = new FileStream();                       
              try{
                                          fileStream.open(file, FileMode.APPEND);
                                          fileStream.writeUTFBytes("");
                                          fileStream.close();
                   }
                  catch(e:Error)
                   {
                                          trace(e.message);
                    }

              • 4. Re: Is a File writable ?
                Loic.Aigon Adobe Community Professional

                Hi and thanks for the time you spent on that topic.

                 


                You were right :-)

                 

                Loic