PDA

View Full Version : function that me controls the existence a file


andrea
04-01-2005, 01:22 AM
It exists in me10 a function that me controls the existence of a direttory or a file and in case I does not exist creates?

Sorry for my English bad.

clausb
04-01-2005, 03:33 AM
Check out your LISP manual. For files, the LISP open function does what you want - see http://www.lisp.org/HyperSpec/Body/fun_open.html. For example:

(setf s (open "foobar" :direction :output :if-does-not-exist :create))


For directories, either use LISP's directory command, or one of the file/directory handling functions documented in the Developer's Kit.

Claus

andrea
04-01-2005, 03:35 AM
For macro in to ME10 ???????

clausb
04-01-2005, 05:39 AM
Oops - sorry. I should be reading those posts more carefully 8-( :(

I don't know too much about OSDD's macro language, but the CREATE_DIRECTORY command might do what you need for directories. If the directory doesn't exist already, it will create it, otherwise issue an error (which you can probably catch using TRAP_ERROR).

For files, OPEN_OUTFILE with option DEL_OLD might do the trick.

Sorry again for the misunderstanding.

Claus

John Scheffel
04-01-2005, 01:24 PM
There may be a better way, but some of our macros use logic like this to test for the existence of a file.

LET Test_file_name 'C:\my_file.txt'
TRAP_ERROR
OPEN_INFILE 1 Test_file_name END
IF (CHECK_ERROR) {file does not exist}
OPEN_OUTFILE 1 Test_file_name
Commands...
ELSE {file exists}
CLOSE_FILE 1
Commands...
END_IF

andrea
04-03-2005, 10:34 PM
thank you very much!

Shaba
04-02-2018, 12:15 AM
Good also for me!