Get path or filename from full path

Syntax

s.getpath([file] [append])
s.getfilename([file] [ext])

 

Parameters

s - str variable.

file - full path to file or folder. Default: s.

append - some string (e.g., another filename) to append. Use "" to prevent appending "\".

ext - if nonzero, get filename with extension.

 

Remarks

getpath extracts the path part from file.

getfilename extracts the filename part from file.

 

Tips

There are many easy to use Windows API functions that can be used to work with paths and URLs. For example, PathFindExtension finds file extension. They are documented in MSDN Library.

 

Example

str s1.getpath("c:\folder\test.txt")
str s2.getfilename("c:\folder\test.txt")
str s3.getfilename("c:\folder\test.txt" 1)
 now s1 is "c:\folder\", s2 is "test", s3 is "test.txt"