Documentation ¶
Index ¶
- Constants
- func Abs(path string) string
- func Basename(path string) string
- func Chdir(dir string) (err error)
- func CheckNotExist(src string) bool
- func CheckPermission(src string) bool
- func Chmod(path string, mode os.FileMode) (err error)
- func Create(path string) (*os.File, error)
- func Dir(path string) string
- func DirNames(path string) ([]string, error)
- func Exist(src string) bool
- func Exists(path string) bool
- func Ext(path string) string
- func ExtName(path string) string
- func GetBytes(path string) []byte
- func GetContents(path string) string
- func GetExt(fileName string) string
- func GetSize(f multipart.File) (int, error)
- func Glob(pattern string, onlyNames ...bool) ([]string, error)
- func IsDir(path string) bool
- func IsEmpty(path string) bool
- func IsFile(path string) bool
- func IsNotExistMkDir(src string) error
- func IsReadable(path string) bool
- func IsWritable(path string) bool
- func Join(paths ...string) string
- func MkDir(src string) error
- func Mkdir(path string) (err error)
- func Move(src string, dst string) (err error)
- func MustOpen(fileName, filePath string) (*os.File, error)
- func Name(path string) string
- func Open(path string) (*os.File, error)
- func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)
- func OpenWithFlag(path string, flag int) (*os.File, error)
- func OpenWithFlagPerm(path string, flag int, perm os.FileMode) (*os.File, error)
- func Pwd() string
- func RealPath(path string) string
- func Remove(path string) (err error)
- func Rename(src string, dst string) error
- func ScanDir(path string, pattern string, recursive ...bool) ([]string, error)
- func ScanDirFile(path string, pattern string, recursive ...bool) ([]string, error)
- func ScanDirFileFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
- func ScanDirFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
- func Stat(path string) (os.FileInfo, error)
- func Temp(names ...string) string
Constants ¶
const ( // Separator for file system. // It here defines the separator as variable // to allow it modified by developer if necessary. Separator = string(filepath.Separator) // DefaultPermOpen is the default perm for file opening. DefaultPermOpen = os.FileMode(0666) // DefaultPermCopy is the default perm for file/folder copy. DefaultPermCopy = os.FileMode(0755) )
Variables ¶
This section is empty.
Functions ¶
func Abs ¶ added in v0.0.33
Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func Basename ¶ added in v0.0.33
Basename returns the last element of path, which contains file extension. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Basename returns a single separator.
Example: Basename("/var/www/file.js") -> file.js Basename("file.js") -> file.js
func Chdir ¶ added in v0.0.33
Chdir changes the current working directory to the named directory. If there is an error, it will be of type *PathError.
func CheckNotExist ¶
func CheckPermission ¶
func Create ¶ added in v0.0.33
Create creates a file with given `path` recursively. The parameter `path` is suggested to be absolute path.
func Dir ¶ added in v0.0.33
Dir returns all but the last element of path, typically the path's directory. After dropping the final element, Dir calls Clean on the path and trailing slashes are removed. If the `path` is empty, Dir returns ".". If the `path` is ".", Dir treats the path as current working directory. If the `path` consists entirely of separators, Dir returns a single separator. The returned path does not end in a separator unless it is the root directory.
Example: Dir("/var/www/file.js") -> "/var/www" Dir("file.js") -> "."
func DirNames ¶ added in v0.0.33
DirNames returns sub-file names of given directory `path`. Note that the returned names are NOT absolute paths.
func Ext ¶ added in v0.0.33
Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot. Note: the result contains symbol '.'.
Example: Ext("main.go") => .go Ext("api.json") => .json
func ExtName ¶ added in v0.0.33
ExtName is like function Ext, which returns the file name extension used by path, but the result does not contain symbol '.'.
Example: ExtName("main.go") => go ExtName("api.json") => json
func GetBytes ¶ added in v0.0.33
GetBytes returns the file content of `path` as []byte. It returns nil if it fails reading.
func GetContents ¶ added in v0.0.33
GetContents returns the file content of `path` as string. It returns en empty string if it fails reading.
func Glob ¶ added in v0.0.33
Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').
Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.
func IsDir ¶ added in v0.0.33
IsDir checks whether given `path` a directory. Note that it returns false if the `path` does not exist.
func IsEmpty ¶ added in v0.0.33
IsEmpty checks whether the given `path` is empty. If `path` is a folder, it checks if there's any file under it. If `path` is a file, it checks if the file size is zero.
Note that it returns true if `path` does not exist.
func IsFile ¶ added in v0.0.33
IsFile checks whether given `path` a file, which means it's not a directory. Note that it returns false if the `path` does not exist.
func IsNotExistMkDir ¶
func IsReadable ¶ added in v0.0.33
IsReadable checks whether given `path` is readable.
func IsWritable ¶ added in v0.0.33
IsWritable checks whether given `path` is writable.
TODO improve performance; use golang.org/x/sys to cross-plat-form
func Mkdir ¶ added in v0.0.33
Mkdir creates directories recursively with given `path`. The parameter `path` is suggested to be an absolute path instead of relative one.
func Move ¶ added in v0.0.33
Move renames (moves) `src` to `dst` path. If `dst` already exists and is not a directory, it'll be replaced.
func Name ¶ added in v0.0.33
Name returns the last element of path without file extension.
Example: Name("/var/www/file.js") -> file Name("file.js") -> file
func OpenFile ¶ added in v0.0.33
OpenFile opens file/directory with custom `flag` and `perm`. The parameter `flag` is like: O_RDONLY, O_RDWR, O_RDWR|O_CREATE|O_TRUNC, etc.
func OpenWithFlag ¶ added in v0.0.33
OpenWithFlag opens file/directory with default perm and custom `flag`. The default `perm` is 0666. The parameter `flag` is like: O_RDONLY, O_RDWR, O_RDWR|O_CREATE|O_TRUNC, etc.
func OpenWithFlagPerm ¶ added in v0.0.33
OpenWithFlagPerm opens file/directory with custom `flag` and `perm`. The parameter `flag` is like: O_RDONLY, O_RDWR, O_RDWR|O_CREATE|O_TRUNC, etc. The parameter `perm` is like: 0600, 0666, 0777, etc.
func Pwd ¶ added in v0.0.33
func Pwd() string
Pwd returns absolute path of current working directory. Note that it returns an empty string if retrieving current working directory failed.
func RealPath ¶ added in v0.0.33
RealPath converts the given `path` to its absolute path and checks if the file path exists. If the file does not exist, return an empty string.
func Remove ¶ added in v0.0.33
Remove deletes all file/directory with `path` parameter. If parameter `path` is directory, it deletes it recursively.
It does nothing if given `path` does not exist or is empty.
func ScanDir ¶ added in v0.0.33
ScanDir returns all sub-files with absolute paths of given `path`, It scans directory recursively if given parameter `recursive` is true.
The pattern parameter `pattern` supports multiple file name patterns, using the ',' symbol to separate multiple patterns.
func ScanDirFile ¶ added in v0.0.33
ScanDirFile returns all sub-files with absolute paths of given `path`, It scans directory recursively if given parameter `recursive` is true.
The pattern parameter `pattern` supports multiple file name patterns, using the ',' symbol to separate multiple patterns.
Note that it returns only files, exclusive of directories.
func ScanDirFileFunc ¶ added in v0.0.33
func ScanDirFileFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
ScanDirFileFunc returns all sub-files with absolute paths of given `path`, It scans directory recursively if given parameter `recursive` is true.
The pattern parameter `pattern` supports multiple file name patterns, using the ',' symbol to separate multiple patterns.
The parameter `recursive` specifies whether scanning the `path` recursively, which means it scans its sub-files and appends the file paths to result array if the sub-file is also a folder. It is false in default.
The parameter `handler` specifies the callback function handling each sub-file path of the `path` and its sub-folders. It ignores the sub-file path if `handler` returns an empty string, or else it appends the sub-file path to result slice.
Note that the parameter `path` for `handler` is not a directory but a file. It returns only files, exclusive of directories.
func ScanDirFunc ¶ added in v0.0.33
func ScanDirFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
ScanDirFunc returns all sub-files with absolute paths of given `path`, It scans directory recursively if given parameter `recursive` is true.
The pattern parameter `pattern` supports multiple file name patterns, using the ',' symbol to separate multiple patterns.
The parameter `recursive` specifies whether scanning the `path` recursively, which means it scans its sub-files and appends the files path to result array if the sub-file is also a folder. It is false in default.
The parameter `handler` specifies the callback function handling each sub-file path of the `path` and its sub-folders. It ignores the sub-file path if `handler` returns an empty string, or else it appends the sub-file path to result slice.
Types ¶
This section is empty.