Force a file creation in a given path ...
Posted: Wed Jun 09, 2004 7:51 am
When creating a new file, it is necessary to check if the path to the desired file exists.
This is not a huge work but can overdo your code and mind ..
Here is a code I use :
This is not a huge work but can overdo your code and mind ..
Here is a code I use :
Code: Select all
;
; Create a file at a given path location creating sub-directories if necessary
;
Procedure DoCreateFile(n.l, FileName.s)
PathPart.s = ""
FilePart.s = GetFilePart(FileName)
If GetPathPart(FileName) <> ""
i = 1
Repeat
Node.s = StringField(FileName, i, "\")
If Node = FilePart
Break
EndIf
PathPart + Node + "\"
If FileSize(PathPart) = -2
Else
CreateDirectory(PathPart)
EndIf
i + 1
Until Node = ""
EndIf
ProcedureReturn CreateFile(n, FileName)
EndProcedure
;
; Test
;
If DoCreateFile(0, "toto\dudule\machin.txt")
CloseFile(0)
EndIf
If DoCreateFile(0, "machin.txt")
CloseFile(0)
EndIf
End