Made the code actually work, updated the docstring to point out that the given file path must exist *and* be accessible from the current working directory of the running program.
This commit is contained in:
parent
c4ac8edce9
commit
6dd96abdcc
1 changed files with 15 additions and 9 deletions
|
|
@ -365,6 +365,7 @@ when defined(windows):
|
||||||
template getFilename(f: expr): expr = $f.cFilename
|
template getFilename(f: expr): expr = $f.cFilename
|
||||||
|
|
||||||
proc skipFindData(f: TWIN32_FIND_DATA): bool {.inline.} =
|
proc skipFindData(f: TWIN32_FIND_DATA): bool {.inline.} =
|
||||||
|
# Note - takes advantage of null delimiter in the cstring
|
||||||
const dot = ord('.')
|
const dot = ord('.')
|
||||||
result = f.cFileName[0].int == dot and (f.cFileName[1].int == 0 or
|
result = f.cFileName[0].int == dot and (f.cFileName[1].int == 0 or
|
||||||
f.cFileName[1].int == dot and f.cFileName[2].int == 0)
|
f.cFileName[1].int == dot and f.cFileName[2].int == 0)
|
||||||
|
|
@ -1997,19 +1998,24 @@ proc getFileInfo*(path: string, followSymlink = true): FileInfo =
|
||||||
|
|
||||||
proc isHidden*(path: string): bool =
|
proc isHidden*(path: string): bool =
|
||||||
## Determines whether a given path is hidden or not. Returns false if the
|
## Determines whether a given path is hidden or not. Returns false if the
|
||||||
## file doesn't exist. On Windows, a file is hidden if the file's 'hidden'
|
## file doesn't exist. The given path must be accessible from the current
|
||||||
## attribute is set. On Unix-like systems, a file is hidden if it starts
|
## working directory of the program.
|
||||||
## with a '.' ."
|
##
|
||||||
|
## On Windows, a file is hidden if the file's 'hidden' attribute is set.
|
||||||
|
## On Unix-like systems, a file is hidden if it starts with a '.' (period)
|
||||||
|
## and is not *just* '.' or '..' ' ."
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
wrapUnary(attributes, getFileAttributesW, path)
|
wrapUnary(attributes, getFileAttributesW, path)
|
||||||
if attributes != -1'i32:
|
if attributes != -1'i32:
|
||||||
result = (attributes and FILE_ATTRIBUTE_HIDDEN) != 0'i32
|
result = (attributes and FILE_ATTRIBUTE_HIDDEN) != 0'i32
|
||||||
else:
|
|
||||||
result = false
|
|
||||||
else:
|
else:
|
||||||
if fileExists(path):
|
if fileExists(path):
|
||||||
result = (path[0] == '.')
|
let
|
||||||
else:
|
fileName = extractFilename(path)
|
||||||
result = false
|
nameLen = len(fileName)
|
||||||
|
if nameLen == 2:
|
||||||
|
result = (fileName[0] == '.') and (fileName[1] != '.')
|
||||||
|
elif nameLen > 2:
|
||||||
|
result = (fileName[0] == '.') and (fileName[3] != '.')
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue