added os.tailDir proc

This commit is contained in:
Araq
2015-07-12 13:30:23 +02:00
parent 994d81461b
commit 27f5c3ceb9
2 changed files with 16 additions and 1 deletions

View File

@@ -621,6 +621,20 @@ proc parentDir*(path: string): string {.
else:
result = ""
proc tailDir*(path: string): string {.
noSideEffect, rtl, extern: "nos$1".} =
## Returns the tail part of `path`..
##
## | Example: ``tailDir("/usr/local/bin") == "local/bin"``.
## | Example: ``tailDir("usr/local/bin/") == "local/bin"``.
## | Example: ``tailDir("bin") == ""``.
var q = 1
if len(path) >= 1 and path[len(path)-1] in {DirSep, AltSep}: q = 2
for i in 0..len(path)-q:
if path[i] in {DirSep, AltSep}:
return substr(path, i+1)
result = ""
proc isRootDir*(path: string): bool {.
noSideEffect, rtl, extern: "nos$1".} =
## Checks whether a given `path` is a root directory

View File

@@ -47,7 +47,8 @@ News
- The nre module has been added, providing a better interface to PCRE than
re.
- The ``expandSymlink`` procedure has been added to the ``os`` module.
- The ``expandSymlink`` proc has been added to the ``os`` module.
- The ``tailDir`` proc has been added to the ``os`` module.
Language Additions
------------------