Focal Point
Checking if file exists

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/6251028331

January 12, 2005, 02:01 PM
HÃ¥kan
Checking if file exists
Trying to check whether a file exists or not using the STATE command.

Have tried with

STATE filename
STATE app\filename
STATE app/filename
STATE approot\app\filename
STATE \\node\sharename\ibi\apps\directory\filename

All returns -1, despite the file actually exist.

We're on WF 5.2.7 on IBM iSeries (AS/400).
Clue anyone?

Tia,
Hakan
January 12, 2005, 03:36 PM
<Pietro De Santis>
Here's some code I found that works:

-SET &FDATE = AYMD(&YYMD,-1,'I8');
-SET &FN2 = '/ibi/srv51/ffs/catalog/sa'|EDIT(&FDATE,'$$999999')|'.ftm' ;
STATE &FN2
-RUN
-IF &RETCODE EQ 0 GOTO CREATED ;
November 06, 2006, 06:22 AM
hammo1j
Might be because your filename contains a blank or a dollar (don't know which).

Have to dos copy to a simple filename and then check that with STATE to get things to work.



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
November 06, 2006, 11:19 AM
hammo1j
Tom

STATE does not work if there's a blank in the filename. Try this:

-DOS ECHO HELLO > "HELLO WORLD.TXT"
-DOS TYPE "HELLO WORLD.TXT"
DOS STATE "HELLO WORLD.TXT"
-RUN
-TYPE &RETCODE
DOS DIR "HELLO WORLD.TXT"
-EXIT

Regards

John



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
November 06, 2006, 12:25 PM
hammo1j
Hakan

Another thing it might be is the Amper Autoprompter's annoying habit of removing backslashes from the code it passes onto the server. If you amper auto prompt you have to double up your backslashes because I think it gets treated as an escape character.

If anyone knows anything more about this and if it gets fixed in a later release, I would be interested to know.

Regards

John



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
November 07, 2006, 11:48 AM
jbmuir
H. Lindholm,

I have experienced a non-functional STATE using FOCUS and unix. The alternative we used was to test the return code of the "ls" command. Hamm01j hinted at this solution, but to be explicit you may be able to deal with this annoying problem by doing something similar:

-DOS DIR "c:\path\to\my file.txt"
-IF &RETCODE NE 0 THEN GOTO OOPS;


WF 7.1.6 moving to WF 7.7, Solaris 10, HTML,PDF,XL
November 07, 2006, 01:57 PM
hammo1j
jbmuir

Yes you guessed right the way round is to copy to a file without the space (which works) and then do the STATE on the target file that contains no spaces.

Here is a solution to check for file name containing spaces C:\HELLO WORLD.TXT. The solution is for windows servers only. I'm sure there are better solutions out there and would love to know of them, but this works ok.

There are 2 levels to this problem

1. Amper autoprompt replaces backslashes in code.

Try this as a .fex .

-SET &FILENAME = 'C:\HELLO WORLD.TXT' ;
-TYPE &FILENAME

It works ok

Now try via the amper autoprompt. (Enter any data)

-SET &DUMMY = &DATA.Please Enter Data. ;
-SET &FILENAME = 'C:\HELLO WORLD.TXT' ;
-TYPE &FILENAME

You can see the backslash is stripped. You can get round this problem by doubling on the back slashes

-* File state_example.fex
-SET &DUMMY = &DATA.Please Enter Data. ;
-SET &FILENAME = 'C:\\HELLO WORLD.TXT' ;
-TYPE &FILENAME

But this does not work if amper autoprompt is not invoked.

-* File state_example.fex
-*SET &DUMMY = &DATA.Please Enter Data. ;
-SET &FILENAME = 'C:\\HELLO WORLD.TXT' ;
-TYPE &FILENAME


2. STATE does not work if there's a blank in the filename. Try this as a .fex:

-DOS ECHO HELLO > "HELLO WORLD.TXT"
-DOS TYPE "HELLO WORLD.TXT"
DOS STATE "HELLO WORLD.TXT"
-RUN
-TYPE &RETCODE
DOS DIR "HELLO WORLD.TXT"
-EXIT

The solution is as follows:


-* File state_example.fex

-* this is the ascii code for backslash
-SET &BS = HEXBYT(92,'A1') ;
-SET &FILENAME = 'C:' | &BS | 'HELLO WORLD.TXT' ;
-TYPE &FILENAME

-* Switch amper autoprompt on
-*SET &DUMMY = &DATA.Please Enter Data. ;

-* Create/Delete the file
-DOS ECHO HELLO > "&FILENAME"
-* WINNT DEL "&FILENAME"

-* can do DOS/WINNT or CMD to pass command to windows based O/S
CMD DEL TEST.TXT > NUL
CMD COPY "&FILENAME" TEST.TXT
CMD STATE TEST.TXT
-RUN

-IF &RETCODE EQ 0 THEN GOTO FILE_EXIST ;
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-TYPE &FILENAME does not exist
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-FILE_EXIST

It's a bit painful but works - someone must have something better!

Regards

John

This message has been edited. Last edited by: hammo1j,



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo