https://github.com/nyaosorg/go-windows-junction
A Go package to create junction points on Windows
https://github.com/nyaosorg/go-windows-junction
go golang junction windows
Last synced: 8 months ago
JSON representation
A Go package to create junction points on Windows
- Host: GitHub
- URL: https://github.com/nyaosorg/go-windows-junction
- Owner: nyaosorg
- License: mit
- Created: 2020-01-28T14:26:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-05-31T11:43:02.000Z (about 1 year ago)
- Last Synced: 2025-05-31T23:43:14.805Z (about 1 year ago)
- Topics: go, golang, junction, windows
- Language: Go
- Homepage: https://pkg.go.dev/github.com/nyaosorg/go-windows-junction
- Size: 16.6 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-windows-junction
===================
[](https://pkg.go.dev/github.com/nyaosorg/go-windows-junction)
[](https://github.com/nyaosorg/go-windows-junction/actions/workflows/go.yml)
A Go package to create [junction points](https://docs.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions) on Windows.
- On **Windows**, it creates a junction point using native system calls.
- On **non-Windows** platforms (Linux, macOS), it falls back to `os.Symlink`.
Junctions are similar to symbolic links but have certain limitations:
- They can only point to directories.
- They do not require elevated privileges (unlike symlinks on some versions of Windows).
- The link target can be read using `os.Readlink`.
This package is useful when writing cross-platform code that creates directory links, and you want consistent behavior on Windows without requiring admin rights.
## Installation
```sh
go get github.com/nyaosorg/go-windows-junction
````
## Usage Example
```go
package main
import (
"os"
"errors"
"github.com/nyaosorg/go-windows-junction"
)
func main1() error {
if len(os.Args) < 3 {
return errors.New("go run example.go TARGET MOUNTPT")
}
if err := junction.Create(os.Args[1], os.Args[2]); err != nil {
return err
}
result, err := os.Readlink(os.Args[2])
if err != nil {
return err
}
println(os.Args[2], " is linked to ", result)
return nil
}
func main() {
if err := main1(); err != nil {
println(err.Error())
os.Exit(1)
}
}
```
### Output Example
```
$ go run example.go ../nyagos nya
nya is linked to C:\Users\hymko\go\src\github.com\nyaosorg\nyagos
```
## Author
[hymkor (HAYAMA Kaoru)](https://github.com/hymkor)
## License
MIT License