Alex Craft
Alex Craft

Reputation: 15336

How to normalise file path in Nim?

The os.normalized_path outputs . instead of the full path.

import os
echo ".".normalized_path

Upvotes: 0

Views: 331

Answers (2)

shirleyquirk
shirleyquirk

Reputation: 1598

@Yardanico's answer is still the right one, but this got too long to leave as a comment.

normalizePath has no knowledge of the current working directory and operates on abstract paths, preserving whether the input is absolute or relative. what it does is:

  • remove extra/trailing slashes: 'foo//bar/' => 'foo/bar'
  • resolve double dots: 'foo/../bar' => 'bar', '../foo' => '../foo'
  • remove initial './': './foo' => 'foo'

it does not:

  • remove initial double dots in absolute paths, i.e. '/..' => '/..'
  • convert path delimiters to the native os delimiter.
  • handle os9's idiosyncratic updirs properly

Upvotes: 4

user5476128
user5476128

Reputation:

That output is correct - it's "normalised" to the current directory, so it's ".", which is a valid path on *nix. If you want to get the full path, do it like this:

import os
echo ".".normalizedPath().absolutePath()

Upvotes: 6

Related Questions