import os
import path/filepath
filepath
包文件路径实现了以与目标操作系统定义的文件路径兼容的方式操作文件名路径的实用程序例程。
filepath包使用正斜杠或反斜杠,具体取决于操作系统。要处理路径,例如始终使用正斜杠的URL而不考虑操作系统,请参阅路径包。
| 方法 | 说明 |
|---|---|
| Constants | |
| Variables | |
| func Abs(path string) (string, error) | 返回绝对路径 |
| func Base(path string) string | 返回路径的最后一个元素 |
| func Clean(path string) string | 返回等同于path的最短路径名 |
| func Dir(path string) string | 返回路径的最后一个元素,通常是路径的目录 |
| func EvalSymlinks(path string) (string, error) | 评估链接,返回路径名 |
| func Ext(path string) string | 文件扩展名 |
| func FromSlash(path string) string | 返回用分隔符替换路径中每个斜杠(’/‘)字符,多个斜杠由多个分隔符替换。 |
| func Glob(pattern string) (matches []string, err error) | Glob将返回匹配pattern或nil的所有文件的名称 |
| func HasPrefix(p, prefix string) bool | 不推荐使用 |
| func IsAbs(path string) bool | 是否为绝对路径 |
| func Join(elem …string) string | 将文件夹路径或文件路径合并 |
| func Match(pattern, name string) (matched bool, err error) | 匹配 |
| func Rel(basepath, targpath string) (string, error) | 根据basepath,更改targpath为绝对路径或相对路径,包含为绝对,不包含则相对 |
| func Split(path string) (dir, file string) | 路径拆分为文件夹路径和文件路径 |
| func SplitList(path string) []string | 拆分路径 |
| func ToSlash(path string) string | 返回用斜杠(’/‘)字符替换路径中每个分隔符,多个分隔符由多个斜杠替换。 |
| func VolumeName(path string) string | win下返回盘符,别的为空 returns leading volume name |
| func Walk(root string, walkFn WalkFunc) error | 遍历root下的所有文件 |
| type WalkFunc | WalkFunc是为Walk访问的每个文件或目录调用的函数的类型。 |
os
| 方法 | 说明 |
|---|---|
| Constants | |
| Variables | |
| func Chdir(dir string) error | |
| func Chmod(name string, mode FileMode) error | |
| func Chown(name string, uid, gid int) error | |
| func Chtimes(name string, atime time.Time, mtime time.Time) error | |
| func Clearenv() | |
| func Environ() []string | |
| func Executable() (string, error) | |
| func Exit(code int) | |
| func Expand(s string, mapping func(string) string) string | |
| func ExpandEnv(s string) string | |
| func Getegid() int | |
| func Getenv(key string) string | |
| func Geteuid() int | |
| func Getgid() int | |
| func Getgroups() ([]int, error) | |
| func Getpagesize() int | |
| func Getpid() int | |
| func Getppid() int | |
| func Getuid() int | |
| func Getwd() (dir string, err error) | |
| func Hostname() (name string, err error) | |
| func IsExist(err error) bool | 指示是否已知错误报告文件或目录已存在 |
| func IsNotExist(err error) bool | 返回是否已知错误报告文件或目录不存在 |
| func IsPathSeparator(c uint8) bool | |
| func IsPermission(err error) bool | |
| func IsTimeout(err error) bool | |
| func Lchown(name string, uid, gid int) error | |
| func Link(oldname, newname string) error | |
| func LookupEnv(key string) (string, bool) | |
| func Mkdir(name string, perm FileMode) error | |
| func MkdirAll(path string, perm FileMode) error | |
| func NewSyscallError(syscall string, err error) error | |
| func Pipe() (r File, w File, err error) | |
| func Readlink(name string) (string, error) | |
| func Remove(name string) error | |
| func RemoveAll(path string) error | |
| func Rename(oldpath, newpath string) error | |
| func SameFile(fi1, fi2 FileInfo) bool | |
| func Setenv(key, value string) error | |
| func Symlink(oldname, newname string) error | |
| func TempDir() string | |
| func Truncate(name string, size int64) error | |
| func Unsetenv(key string) error | |
| func UserCacheDir() (string, error) | |
| type File | |
| func Create(name string) (*File, error) | |
| func NewFile(fd uintptr, name string) *File | |
| func Open(name string) (*File, error) | |
| func OpenFile(name string, flag int, perm FileMode) (*File, error) | 打开文件 |
| func (f *File) Chdir() error | 将当前目录更改为文件 |
| func (f *File) Chmod(mode FileMode) error | |
| func (f *File) Chown(uid, gid int) error | |
| func (f *File) Close() error | 关闭 |
| func (f *File) Fd() uintptr | |
| func (f *File) Name() string | 显示打开的文件名 |
| func (f *File) Read(b []byte) (n int, err error) | 读取len(b)个字节 |
| func (f *File) ReadAt(b []byte, off int64) (n int, err error) | |
| func (f *File) Readdir(n int) ([]FileInfo, error) | |
| func (f *File) Readdirnames(n int) (names []string, err error) | |
| func (f *File) Seek(offset int64, whence int) (ret int64, err error) | |
| func (f *File) SetDeadline(t time.Time) error | |
| func (f *File) SetReadDeadline(t time.Time) error | |
| func (f *File) SetWriteDeadline(t time.Time) error | |
| func (f *File) Stat() (FileInfo, error) | 返回描述文件的FileInfo结构 |
| func (f *File) Sync() error | 将缓存的文件写入到磁盘 |
| func (f *File) Truncate(size int64) error | 截断文件 |
| func (f *File) Write(b []byte) (n int, err error) | 将b 写入文件,返回写入的字节数 |
| func (f *File) WriteAt(b []byte, off int64) (n int, err error) | 将b写入,偏移off |
| func (f *File) WriteString(s string) (n int, err error) | 写入string |
| type FileInfo | |
| func Lstat(name string) (FileInfo, error) | |
| func Stat(name string) (FileInfo, error) | 返回状态 |
| type FileMode | |
| func (m FileMode) IsDir() bool | |
| func (m FileMode) IsRegular() bool | |
| func (m FileMode) Perm() FileMode | |
| func (m FileMode) String() string | |
| type LinkError | |
| func (e *LinkError) Error() string | |
| type PathError | |
| func (e *PathError) Error() string | |
| func (e *PathError) Timeout() bool | |
| type ProcAttr | |
| type Process | |
| func FindProcess(pid int) (*Process, error) | |
| func StartProcess(name string, argv []string, attr ProcAttr) (Process, error) | |
| func (p *Process) Kill() error | |
| func (p *Process) Release() error | |
| func (p *Process) Signal(sig Signal) error | |
| func (p Process) Wait() (ProcessState, error) | |
| type ProcessState | |
| func (p *ProcessState) Exited() bool | |
| func (p *ProcessState) Pid() int | |
| func (p *ProcessState) String() string | |
| func (p *ProcessState) Success() bool | |
| func (p *ProcessState) Sys() interface{} | |
| func (p *ProcessState) SysUsage() interface{} | |
| func (p *ProcessState) SystemTime() time.Duration | |
| func (p *ProcessState) UserTime() time.Duration | |
| type Signal | |
| type SyscallError | |
| func (e *SyscallError) Error() string | |
| func (e *SyscallError) Timeout() bool |
os/user
允许按名称或ID查找用户帐户。
os/exec
运行外部命令。