# \[solved\] check if a file exists on Harddisk?

**URL:** <https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, NaturalONE, NaturalONE-Full-Edition\
**Created:** [February 28, 2014, 12:07pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762 "2014-02-28T12:07:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ma\_We](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Ma\_We](https://techcommunity.softwareag.com/u/Ma_We)\
**Post date:** [February 28, 2014, 12:07pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/1 "2014-02-28T12:07:18Z")

</div>

Hello!  
I’m on NaturalOne Ajax 8.2 with the following question:  
In a main program, I have to check if a file exists on hard disk. I’ve tried:

```auto
 
REQUEST DOCUMENT FROM #fileonhdd RESPONSE #FileExistRPCode
 
```

(#fileonhdd is filled with C:/TEMP/TEST.TXT)

But on this way I get an error: " wrong protocol…" (maybe just only for http/https?)

How can I check if a file exists on Harddisk?

Thank you ver much,  
Matthias

---

<div class="post-metadata">

**Author:** ![mwessjoh](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mwessjoh](https://techcommunity.softwareag.com/u/mwessjoh)\
**Post date:** [February 28, 2014, 12:55pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/2 "2014-02-28T12:55:28Z")

</div>

Hi,

we wrote an Natural-Modul which checks this with unix utilities:

Directory-Check:  
COMPRESS ‘"’ P-DIR ‘"’ INTO OS-COMMAND LEAVING NO  
COMPRESS ‘test -d’ OS-COMMAND INTO OS-COMMAND  
\*  
CALLNAT ‘USR1052N’ USR1052L  
P-RC := RESPONSE

File-Check:  
COMPRESS ‘"’ P-DIR ‘"’ INTO OS-COMMAND LEAVING NO  
COMPRESS ‘test -f’ OS-COMMAND INTO OS-COMMAND  
\*  
CALLNAT ‘USR1052N’ USR1052L  
P-RC := RESPONSE

P-RC = 0 =\> OK  
P-RC \> 0 =\> not OK

Maybe there is an Windows command …

best regards  
Markus Wessjohann

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [February 28, 2014, 1:01pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/3 "2014-02-28T13:01:04Z")

</div>

If you define C:/TEMP/TEST.TXT as a work file, you could do a READ WORK FILE for the first record.

---

<div class="post-metadata">

**Author:** ![Ma\_We](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Ma\_We](https://techcommunity.softwareag.com/u/Ma_We)\
**Post date:** [February 28, 2014, 1:08pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/4 "2014-02-28T13:08:08Z")

</div>

@ Steve Robinson  
yes, but in this case I whould get an ERROR if the file does not exist, and I must not go into an ERROR :?

thank you very much,  
matthias

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [February 28, 2014, 3:24pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/5 "2014-02-28T15:24:07Z")

</div>

Use an ON ERROR clause.

---

<div class="post-metadata">

**Author:** ![Ma\_We](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Ma\_We](https://techcommunity.softwareag.com/u/Ma_We)\
**Post date:** [March 4, 2014, 2:07pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/6 "2014-03-04T14:07:28Z")

</div>

I did it with DEFINE/READ WORK FILE. It works, but just only once (ON ERROR). When I come a second time to the  
READ WORKFILE statement and ERROR-NR 1599 in my program, this ON ERROR-Block is ignored.

Does my Program “forget” this ON ERROR-BLOCK?  
Can you explane me why?

```auto
ON ERROR
IF *ERROR-NR = 1599
PROCESS PAGE UPDATE FULL AND SEND EVENT 'nat:page.message'
  WITH PARAMETERS
   NAME 'type' VALUE 'E'
   NAME 'short' VALUE 'No File found'
 END-PARAMETERS
END-IF 
END-ERROR
```

Thank you very much,  
Matthias

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [March 4, 2014, 2:42pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/7 "2014-03-04T14:42:17Z")

</div>

ON ERROR is a non procedural clause in Natural. More importantly, it interrupts the execution of a program.

With the exception of a record-held error (3145), which permits execution to continue via RETRY, your program ends after the ON ERROR clause ends.

Thus, for anything to happen again, you must have logic in the ON ERROR clause that continues execution of your “system”. For example, you might FETCH a driver program to your existing program. You could use the stack, or \*COM, to “tell” the driver what happened.

steve

---

<div class="post-metadata">

**Author:** ![mwessjoh](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mwessjoh](https://techcommunity.softwareag.com/u/mwessjoh)\
**Post date:** [March 5, 2014, 9:08am UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/8 "2014-03-05T09:08:45Z")

</div>

Build a new modul CHECKFILE with the ON ERROR cause:

like this:  
P-FILEEXITS := 0  
DEFINE WORK FILE 32 P-FILENAME …  
CLOSE WORK FILE 32

ON ERROR  
P-FILEEXITS := 1  
ESCAPE MODULE  
END-ERROR

Everytime you want to read a file, you can call the modul, to check if it existing.

The problem is you must be sure, that no other modul is using workfilenr 32 ☹

best regards  
Markus Wessjohann

---

<div class="post-metadata">

**Author:** ![Ma\_We](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Ma\_We](https://techcommunity.softwareag.com/u/Ma_We)\
**Post date:** [March 5, 2014, 3:18pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/9 "2014-03-05T15:18:08Z")

</div>

did it like you’ve written, it works! 😃  
thank you very much!  
Matthias

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:30pm UTC](https://techcommunity.softwareag.com/t/solved-check-if-a-file-exists-on-harddisk/174762/10 "2021-04-02T15:30:27Z")

</div>


