GO文件操作的大多数函数在os包里,使用之前需要先引入os包,然后使用os.FunctionName进行相关文件操作。
目录操作
1、创建目录
func Mkdir(name string, perm FileMode) error
Mkdir creates a new directory with the specified name and permission bits. If there is an error, it will be of type *PathError.
2、级联创建目录
func MkdirAll(path string, perm FileMode) error
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
3、删除目录
func Remove(name string) error
Remove removes the named file or directory. If there is an error, it will be of type *PathError.
4、级联删除目录
func RemoveAll(path string) error
RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
目录操作
1、创建目录
func Mkdir(name string, perm FileMode) error
Mkdir creates a new directory with the specified name and permission bits. If there is an error, it will be of type *PathError.
2、级联创建目录
func MkdirAll(path string, perm FileMode) error
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
3、删除目录
func Remove(name string) error
Remove removes the named file or directory. If there is an error, it will be of type *PathError.
4、级联删除目录
func RemoveAll(path string) error
RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).