Skip to content

Nim module for filename matching with UNIX shell patterns

License

Notifications You must be signed in to change notification settings

achesak/nim-fnmatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

About

nim-fnmatch is a Nim module for filename matching with UNIX shell patterns. It is based on Python's fnmatch module in the standard library.

Examples:

# Test if a filename matches a pattern, ignoring case.
let filename: string = "EXAMPLE.TXT"
let pattern: string = "*.txt"
var matches: bool = fnmatch(filename, pattern)
echo(matches) # outputs true

# Test if a filename matches a pattern, taking into account case.
# Using same filename and pattern as previous example.
matches = fnmatchcase(filename, pattern)
echo(matches) # outputs false

# Filter a list of names to get a subset that matches a pattern.
let names: seq[string] = @["list", "of", "test.txt", "FILES.TXT", "fnmatch.nim", "fnmatch.testfile"]
var filtered: seq[string] = filter(names, "*.t*)
echo(filtered)
# outputs @["test.txt, "FILES.TXT", "fnmatch.testfile"]

# filter() can also filter based on case, if true is given as the third parameter.
filtered = filter(names, "*.t*", true)
echo(filtered)
# outputs @["test.txt", "fnmatch.testfile"]

License

nim-fnmatch is released under the MIT open source license.

About

Nim module for filename matching with UNIX shell patterns

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages