Expand my Community achievements bar.

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

Avatar

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

2 Replies

Avatar

Former Community Member

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

Avatar

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