Restored from previous forum. Originally posted by Roxxler.
Hi,
PureBasic stellt keine Funktion zur Verfügung, welche prüft ob eine Datei
oder ein Verzeichnis existiert. Hier eine kleine Procedur, die Abhilfe schafft.
There ist no command in PureBasic to check if a file or a directory will exist.
Here a little procedure which will help
Procedure.b ExistFile(path$)
;
; Das Unterprogramm prüft mittels der DOS-Funktion Lock() ob eine
; Datei oder ein Verzeichnis existiert.
; The procedure checks if a given file or directory is present.
; This will be done via the Lock() function of the dos.library.
;
; Paramater: path$ = Zu prüfende Datei oder zu prüfendes Verzeichnis
; the file or directory to check for
; Rückgabe : 0 = FALSE, Datei oder Verzeichnis existiert nicht
; Returns: FALSE, file or directory doesn't exists
; -1 = TRUE, Datei oder Verzeichnis existiert
; TRUE, file or directory is present
;
; Voraussetzungen: Die dos.library muß geöffnet sein (OpenDosLibrary_(version.l)).
; Wird von PureBasic am Programmende wieder geschlossen.
; Requirements: You have to open the dos.library (OpenDosLibrary_(version.l)).
; PureBasic will close the library automatically at the programend.
lock.l=Lock_(path$,-2)
If lock0
UnLock_(lock)
ProcedureReturn -1
Else
ProcedureReturn 0
EndIf
EndProcedure
DosBase.l=OpenDosLibrary_(36)
If DosBase0
ok.b=ExistFile("ram:test.info")
If ok=-1
PrintN("File or directory exists")
Else
PrintN("File or directory doesn't exist")
EndIf
Else
Printn("Cannot open dos.library")
Endif
End
Procedure ExistFile()
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Fangbeast.
In PureBasic, you can check (more or less) for a file's existence (or if it's damaged) by using the returned state of the OpenFile or ReadFile command.
If you refer to the manual, "If OpenFile(FileNum, "C:\MyFileName.txt") 0
if the returned state is 0, the file doesn't exist or is damaged. If it's not 0, it exists and it's okay to open.
Regards
Fangles
Hi Roxxler, that's not true for files exactly but I know what you mean.There ist no command in PureBasic to check if a file or a directory will exist.
Here a little procedure which will help
In PureBasic, you can check (more or less) for a file's existence (or if it's damaged) by using the returned state of the OpenFile or ReadFile command.
If you refer to the manual, "If OpenFile(FileNum, "C:\MyFileName.txt") 0
if the returned state is 0, the file doesn't exist or is damaged. If it's not 0, it exists and it's okay to open.
Regards
Fangles
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Fangbeast.
/me hits brain with dead fish
Fangles
Yes, I forgot that. Jus trying to show that they both return a 'state' so you can tell if they exist or not :)Better use ReadFile() because OpenFile() will create it if it doesn't exists.
Fred - AlphaSND
/me hits brain with dead fish
Fangles
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Roxxler.
Greetings ..
Roxxler
Yes, you are right. You can check files in this way, but not any existing directories.Hi Roxxler, that's not true for files exactly but I know what you mean.There ist no command in PureBasic to check if a file or a directory will exist.
Here a little procedure which will help
In PureBasic, you can check (more or less) for a file's existence (or if it's damaged) by using the returned state of the OpenFile or ReadFile command.
If you refer to the manual, "If OpenFile(FileNum, "C:\MyFileName.txt") 0
if the returned state is 0, the file doesn't exist or is damaged. If it's not 0, it exists and it's okay to open.
Regards
Fangles
Greetings ..
Roxxler