2 Replies Latest reply on Feb 27, 2013 8:37 AM by jjcarneiro

    Is there a way to know if a file REALLY exists?

    jjcarneiro Level 1

      If a large file is being copied into a diretory. FileUtilService.Exists will return TRUE. That only indicates a 'directory entry' exists, not that the file is there and available.

       

      Is there a way to get that information? If you get Windows' file proeprties it will tell you that the file is 'locked', but I do not see any FileUtilService to get that info.

       

      Is there a solution to that?

       

      TIA

      julio

        • 1. Re: Is there a way to know if a file REALLY exists?
          Steve Bishop Level 2

          Possibly you could do it in an Execute Script step using methods available on the Java File object.

          • 2. Re: Is there a way to know if a file REALLY exists?
            jjcarneiro Level 1

            Hi Steve,

             

            That is exactly what I ended up doing.

            For future reference here is the script code I used, seems to do the job:

             

            File filename =pathToFile( patExecContext.getProcessDataStringValue("/process_data/@filepath"));

            boolean doesFileReallyExists = filename.canWrite();

            if (doesFileReallyExists ) {

                        try {

                            ran = new RandomAccessFile(filename , "rw");

                             try {

                                if (ran != null) ran.close();

                             }  catch (IOException ioe) {

                             }

                        } catch (Exception ex) {

                            doesFileReallyExists = false;

                       }

            }

            patExecContext.setProcessDataBooleanValue("/process_data/@fileExists", doesFileReallyExists );

             

            One caveat of that script is that LCES needs R/W access to the file/document.

             

            hth

            julio