fs

package
v0.0.0-...-e54033a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2022 License: GPL-3.0 Imports: 6 Imported by: 2

README

fs

An easy to use filesystem copy/move library in go, it works exactly the same as Bash.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseNameWithoutExt

func BaseNameWithoutExt(filename string) string

BaseNameWithoutExt return basename without extension of `filename`, in which `filename` may contains directory.

func Copy

func Copy(src, dest string) error

Copy copies src to dest, doesn't matter if src is a directory or a file

func IsWritable

func IsWritable(path string) (isWritable bool, err error)

IsWritable test if directory path is writable or not

func LocateFile

func LocateFile(protofile string, protodirs []string) (string, error)

LocateFile 定位protofile目录路径

要想保证protofile能够被搜索到,protodirs需要提供protofile的父路径,不能是父路径的父路径

func Move

func Move(src, dst string) error

Move move `src` to `dest`

the behavior of fs.Move is consistent with bash shell `mv` command:

when move a file, actions are following: ------------------------------------------------------------------------------------------------ | No. | src existed | src type | dst existed | dst type | behavior | ------------------------------------------------------------------------------------------------ | 1 | False | - | - | - | error: No such file or directory | ------------------------------------------------------------------------------------------------ | 2 | True | File | False | - | if dir(dst) existed: | | | | | | | - Yes, is dir, mv `src` to dir(dst) | | | | | | | - Yes, not dir, err: Not a directory | | | | | | | - No, err: No such file or directory | ------------------------------------------------------------------------------------------------ | 3 | True | File | True | Folder | if dst/basename(src) existed: | | | | | | | - Yes, mv `src` to dst/basename(src) | | | | | | | - No, mv `src` to dst/basename(src) | ------------------------------------------------------------------------------------------------ | 4 | True | File | True | File | mv `src` to dst | ------------------------------------------------------------------------------------------------

when move a directory, actions are following: ------------------------------------------------------------------------------------------------ | 5 | True | Folder | False | - | if dir(dst) existed: | | | | | | | - Yes, is dir, mv `src` to dir(dst) | | | | | | | - Yes, not dir, err: File Exists | | | | | | | - No, err: No such file or directory | ------------------------------------------------------------------------------------------------ | 6 | True | Folder | True | File | error: File Already Existed | ------------------------------------------------------------------------------------------------ | 7 | True | Folder | True | Folder | t = dst/basename(src), if t existed: | | | | | | | - Yes, t empty, mv src to t | | | | | | | - t notempty, err: t Not empty | | | | | | | - No, mv src to t | ------------------------------------------------------------------------------------------------

Why keep the behavior consistent? It makes the usage much more friendly when it behaves as users expected.

func PrepareOutputdir

func PrepareOutputdir(outputdir string) error

PrepareOutputdir create outputdir if it doesn't exist, return error if `outputdir` existed while it is not a directory, return error if any other error occurs.

func UniqFilePath

func UniqFilePath(dirs []string) []string

UniqFilePath 文件系统路径去重

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL