GetPath

It is useful to know which folder a program is running from. You can then save a configuration file or documents to that folder, or load a picture, data or whatever. It avoids the problem of having to include a fixed path within a program.

The full path to the program (including filename), can be obtained by reading Cmd$(1). You then need to read the string backwards until you find the first backslash. Then you've found the path. The program below illustrates this. (Always make strings using file paths 255 characters - the maximum - as paths can be very long.)

PROC getpath:
Local path$(255),i%
        
i%=Len(Cmd$(1))
Do
  i%=i%-1
Until Mid$(Cmd$(1),i%,1)="\"
path$=Left$(Cmd$(1),i%)
        
print "Cmd$(1) = ";cmd$(1)
print
print "Path = ";path$
get

ENDP
 

Back to RAW Computing

  Psion home page