-
-
Save erning/4316644 to your computer and use it in GitHub Desktop.
golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
put this script in the path like | |
assumed /tmp (cwd) | |
/tmp/dir1/dir2/path.go | |
/tmp/dir3 symlinked to /tmp/dir1/dir2 | |
and run with | |
gorun ../tmp/dir3/path.go | |
or build path.go and run with ../tmp/dir3/path | |
*/ | |
package main | |
import "os" | |
import "fmt" | |
import "path/filepath" | |
func main() { | |
p := os.Args[0] | |
var s string | |
fmt.Printf("original: %s\n", p) | |
s = filepath.Clean(p) | |
fmt.Printf("normpath: %v\n", s) | |
s, _ = filepath.Abs(p) | |
fmt.Printf("abspath: %v\n", s) | |
s, _ = filepath.EvalSymlinks(p) | |
s, _ = filepath.Abs(s) | |
fmt.Printf("realpath: %v\n", s) | |
s, _ = os.Getwd() | |
s = filepath.Join(s, p) | |
fmt.Printf("normpath(join(getcwd(), p): %v\n", s) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# put this script in the path like | |
# assumed /tmp (cwd) | |
# /tmp/dir1/dir2/path.py | |
# /tmp/dir3 symlinked to /tmp/dir1/dir2 | |
# | |
# and run with | |
# python ../tmp/hello3/path.py | |
from os import getcwd | |
from os.path import normpath, abspath, realpath, join | |
import sys | |
p = sys.argv[0] | |
print "origin: %s" % p | |
print "normpath: %s" % normpath(p) | |
print "abspath: %s" % abspath(p) | |
print "realpath: %s" % realpath(p) | |
print "normpath(join(getcwd(), p): %s" % normpath(join(getcwd(), p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment