Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
Copy copies a file from src to dst. It handles files and symbolic links.
Example ¶
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/exonlabs/go-utils/pkg/abc/fsx"
)
func main() {
tmpDir := os.TempDir()
srcPath := filepath.Join(tmpDir, "srcfile.txt")
dstPath := filepath.Join(tmpDir, "srcfile_copy.txt")
err := fsx.Copy(srcPath, dstPath)
if err != nil {
fmt.Println(err)
}
}
func CopyDir ¶
CopyDir copies a directory and its contents from src to dst.
Example ¶
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/exonlabs/go-utils/pkg/abc/fsx"
)
func main() {
tmpDir := os.TempDir()
srcDir := filepath.Join(tmpDir, "srcdir")
dstDir := filepath.Join(tmpDir, "srcdir_copy")
err := fsx.CopyDir(srcDir, dstDir)
if err != nil {
fmt.Println(err)
}
}
func ParsePath ¶
ParsePath validates and returns the absolute path.
Example ¶
package main
import (
"fmt"
"github.com/exonlabs/go-utils/pkg/abc/fsx"
)
func main() {
paths := []string{
"",
" ",
"/",
"/tmp/..",
"/tmp/dir1/../",
"/tmp/dir1/../srcfile.txt",
}
for _, path := range paths {
p, err := fsx.ParsePath(path)
if err == nil {
fmt.Printf("\"%s\" --> \"%s\"\n", path, p)
} else {
fmt.Printf("\"%s\" --> err: %s\n", path, err.Error())
}
}
}
Output: "" --> err: invalid path " " --> err: invalid path "/" --> "/" "/tmp/.." --> "/" "/tmp/dir1/../" --> "/tmp" "/tmp/dir1/../srcfile.txt" --> "/tmp/srcfile.txt"
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.