No description
Find a file
2022-03-03 16:45:20 +01:00
src Repaired package due version increase in nim language. 2022-03-03 16:45:20 +01:00
tests Repaired package due version increase in nim language. 2022-03-03 16:45:20 +01:00
.editorconfig Initial commit of Pathname for Nim. 2020-01-24 15:17:33 +01:00
.gitignore Pathname further implemented. 2020-02-10 20:39:05 +01:00
nim.cfg Initial commit of Pathname for Nim. 2020-01-24 15:17:33 +01:00
pathname.nimble Initial commit of Pathname for Nim. 2020-01-24 15:17:33 +01:00
README.md Pathname and FileUtils incl. Tests further improved. 2020-08-24 17:48:28 +02:00

Nim Pathname

nimble

Introduction

This is a port of the pathname library from the ruby-standard-library.

Get Started

Install Nim Pathname

$ nimble install nimpathname

Use Nim Pathname

import pathname

# Construct pathname ...
let aPath        = Pathname.new("/var/lib/a_directory/")
let currPath     = Pathname.new()
let tempPath     = Pathname.fromTempDir()
let appDirPath   = Pathname.fromAppDir()
let rootPath     = Pathname.fromRootDir()
let userHomePath = Pathname.fromUserHomeDir()
let userDataPath = Pathname.fromUserConfigDir()

# Convert back to String ...
echo aPath.toPathStr()

# Working with Pathname
echo aPath.isAbsolute()
echo aPath.isRelative()
echo aPath.isExisting()
echo aPath.isNotExisting()
echo aPath.isRegularFile()
echo aPath.isDirectory()
echo aPath.isSymlink()
echo aPath.isPipeFile()
echo aPath.isDeviceFile()

userDataPath.join("MyApp").createDirectory()
userDataPath.join("MyApp","config.ini").touch()

echo Pathname.fromRootDir("bin","cat").isExisting()
echo Pathname.fromRootDir("bin","cat").isExecutable()

echo Pathname.fromUserConfigDir("MyApp","config.ini").fileSizeInBytes()
echo Pathname.fromUserConfigDir("MyApp","config.ini").userId()

echo Pathname.fromUserConfigDir("MyApp","config.ini").getLastAccessTime()
echo Pathname.fromUserConfigDir("MyApp","config.ini").getLastChangeTime()
echo Pathname.fromUserConfigDir("MyApp","config.ini").getLastStatusChangeTime()

echo aPath("..//./config.d/././//./config.ini).cleanpath()
echo aPath("..//./config.d/././//./config.ini).normalize()

# Example: Create Application-Config-Directory ...
Pathname.fromUserConfigDir("MyApp").tap do (confDir: Pathname):
  confDir.createDirectory(mode=0o750)
  confDir.createyDirectory("exports")
  confDir.createEmptyDirectory("imports")
  confDir.createEmptyDirectory("run")
  confDir.createRegularFile("config.ini")
  confDir.createFile("app.pid")
  confDir.touch("run/")
  confDir.touch("last_started")
  ...
  confDir.removeRegularFile("app.pid")
  confDir.removeEmptyDirectory("exports")
  confDir.removeDirectoryTree("imports")
  ...
  confDir.remove()

Develop

Running Tests

$ nimble test