Awkl
Loading...
Searching...
No Matches
path Namespace Reference

Filesystem path related operations for different platforms. More...

Functions

unassigned osSeps (string p)
 Recompute path configurations for a given gawk platform.
 
number isSep (char c)
 Check if a character is a path separator.
 
string basename (string p)
 Get the last component of a pathname.
 
string dirname (string p)
 Gets the parent directory name of a pathname.
 
unassigned splitExt (string p, array< string > R)
 Splits a path into its file path and its extension.
 
string extension (string p)
 Get the extension portion of a pathname.
 
number isAbs (string p)
 Check whether a pathname is absolute.
 
number isRel (string p)
 Check whether a pathname is relative.
 
unassigned splitDrive (string p, array< string > R)
 Split a pathname into its drive and and path components.
 
number hasDevice (string p)
 Check whether a pathname has a device prefix.
 
string root (string p)
 Get the root directory of a path.
 
number isRootDir (string p)
 Check whether a path is the root directory.
 
number isCrossValidName (string f)
 Check if a filename is valid for cross-platform regular use.
 
number isValidName (string f)
 Check if a filename is valid for regular use in the current path platform.
 
string normcase (string p)
 Normalize the casing and separator of a pathname for the current platform.
 
string normalize (string p, number keep_f=0, number case_f=1)
 Normalize a pathname.
 

Variables

string sep
 File path separator.
 
string altsep
 Alternative file path separator.
 
string delim
 Search path separator.
 
string curdir
 Current directory symbol.
 
string pardir
 Parent directory symbol.
 
string extsep
 Extension symbol.
 
string cased
 Whether file system is case sensitive or not.
 
string droot
 Whether double slash // is a distinct file system root or not.
 
string drel
 Whether a drive letter can be in a relative path or not.
 

Detailed Description

Filesystem path related operations for different platforms.

This module offers functions for querying information on filesystem paths for different platforms (currently Windows and Unix) depending on settable variables. The default path configurations depend on PROCINFO["platform"]

The expected results of many of these functions were considered based on existing path libraries in other languages, preferring the C or C++ way specially in edge cases were they tend to differ.

References:

For future directions:

Function Documentation

◆ basename()

string path::basename ( string p)

Get the last component of a pathname.

Parameters
pFile path name
Returns
Last component of the pathname

◆ dirname()

string path::dirname ( string p)

Gets the parent directory name of a pathname.

Parameters
pFile path name
Returns
Parent directory name of the pathname

◆ extension()

string path::extension ( string p)

Get the extension portion of a pathname.

Parameters
pFile path name
Returns
Extension of the pathname
Note
Similar to the C++ and NodeJS way of getting the extension, not the Python way

◆ hasDevice()

number path::hasDevice ( string p)

Check whether a pathname has a device prefix.

Parameters
pFile path name
Returns
1 if the pathname has a device prefix. 0 otherwise

◆ isAbs()

number path::isAbs ( string p)

Check whether a pathname is absolute.

Parameters
pFile path name
Returns
1 if the pathname is absolute. 0 otherwise

◆ isCrossValidName()

number path::isCrossValidName ( string f)

Check if a filename is valid for cross-platform regular use.

Parameters
fFile name. Not a whole path
Returns
1 if the path is cross-platform valid. 0 otherwise
Note
Platforms taken into account are Windows, and POSIX Unix-like systems
Todo
maximum length parameter, defaulting to 255 (bytes)

◆ isRel()

number path::isRel ( string p)

Check whether a pathname is relative.

Parameters
pFile path name
Returns
1 if the pathname is relative. 0 otherwise

◆ isRootDir()

number path::isRootDir ( string p)

Check whether a path is the root directory.

Parameters
pFile path name
Returns
1 if the path is a root directory for the current platform. 0 otherwise

◆ isSep()

number path::isSep ( char c)

Check if a character is a path separator.

Parameters
cCharacter to test
Returns
1 if it is a separator. 0 otherwise

◆ isValidName()

number path::isValidName ( string f)

Check if a filename is valid for regular use in the current path platform.

Parameters
fFile name. Not a whole path
Returns
1 if the path is valid for current platform. 0 otherwise
Note
This doesn't consider valid the special directory names like . or .. on Unix

◆ normalize()

string path::normalize ( string p,
number keep_f = 0,
number case_f = 1 )

Normalize a pathname.

Parameters
pFile path name to normalize
keep_f1 to keep trailing separators
case_f1 to normalize the case on case-insensitive platforms
Returns
Normalized path. Taking care of ., .. and repeated separators
Todo
option to preserve trailing sep

◆ normcase()

string path::normcase ( string p)

Normalize the casing and separator of a pathname for the current platform.

Parameters
pFile path name
Returns
Path name with its casing and separator normalize if applies for the current platform

◆ osSeps()

unassigned path::osSeps ( string p)

Recompute path configurations for a given gawk platform.

Parameters
pGawk platform as in PROCINFO["platform"]
Returns

◆ root()

string path::root ( string p)

Get the root directory of a path.

Parameters
pFile path name
Returns
Root directory for the path

◆ splitDrive()

unassigned path::splitDrive ( string p,
array< string > R )

Split a pathname into its drive and and path components.

Parameters
pFile path name
[out]RArray to fill with:
  1. Drive label portion
  2. File path name without its drive label portion
Returns
Todo
UNC handling, check Nim's ntpath/splitDrive

◆ splitExt()

unassigned path::splitExt ( string p,
array< string > R )

Splits a path into its file path and its extension.

Parameters
pFile path name
[out]RArray to fill with:
  1. File path name without its extension portion
  2. Extension portion
Returns

Variable Documentation

◆ altsep

string path::altsep

Alternative file path separator.

◆ cased

string path::cased

Whether file system is case sensitive or not.

◆ curdir

string path::curdir

Current directory symbol.

◆ delim

string path::delim

Search path separator.

◆ drel

string path::drel

Whether a drive letter can be in a relative path or not.

◆ droot

string path::droot

Whether double slash // is a distinct file system root or not.

◆ extsep

string path::extsep

Extension symbol.

◆ pardir

string path::pardir

Parent directory symbol.

◆ sep

string path::sep

File path separator.