filesystem

package
v1.0.1008 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: Apache-2.0 Imports: 11 Imported by: 8

Documentation

Index

Constants

View Source
const (
	ModeDir        = os.ModeDir        // d: is a directory
	ModeAppend     = os.ModeAppend     // a: append-only
	ModeExclusive  = os.ModeExclusive  // l: exclusive use
	ModeTemporary  = os.ModeTemporary  // T: temporary file; Plan 9 only
	ModeSymlink    = os.ModeSymlink    // L: symbolic link
	ModeDevice     = os.ModeDevice     // D: device file
	ModeNamedPipe  = os.ModeNamedPipe  // p: named pipe (FIFO)
	ModeSocket     = os.ModeSocket     // S: Unix domain socket
	ModeSetuid     = os.ModeSetuid     // u: setuid
	ModeSetgid     = os.ModeSetgid     // g: setgid
	ModeCharDevice = os.ModeCharDevice // c: Unix character device, when ModeDevice is set
	ModeSticky     = os.ModeSticky     // t: sticky
	ModeIrregular  = os.ModeIrregular  // ?: non-regular file; nothing else is known about this file

	// Mask for the type bits. For regular files, none will be set.
	ModeType = os.ModeType

	// Unix permission bits, 0o777
	ModePerm = os.ModePerm
)
View Source
const (
	// 只读模式
	O_RDONLY int = os.O_RDONLY
	// 只写模式
	O_WRONLY int = os.O_WRONLY
	// 可读可写
	O_RDWR int = os.O_RDWR
	// 追加内容
	O_APPEND int = os.O_APPEND
	// 创建文件,如果文件不存在
	O_CREATE int = os.O_CREATE
	// 与创建文件一同使用,文件必须存在
	O_EXCL int = os.O_EXCL
	// 打开一个同步的文件流
	O_SYNC int = os.O_SYNC
	// 如果可能,打开时缩短文件
	O_TRUNC int = os.O_TRUNC
)

Flags 列表

Variables

This section is empty.

Functions

func Abs added in v1.0.1003

func Abs(path string) (string, error)

返回 path 代表的绝对路径

func AddMimeType added in v1.0.1007

func AddMimeType(ext string, mime string)

添加数据

func AllFiles added in v1.0.1003

func AllFiles(directory string) ([]string, error)

全部文件

func Append added in v1.0.1003

func Append(path string, data string) error

尾部添加

func Basename added in v1.0.1003

func Basename(path string) string

文件目录名称

func Chmod added in v1.0.1003

func Chmod(path string, mode uint32) error

设置权限

func Clean added in v1.0.1003

func Clean(path string) string

规整化路径

func CleanDirectory added in v1.0.1003

func CleanDirectory(directory string) error

清空文件夹

func Close added in v1.0.1003

func Close(fd *os.File) error

关闭

func Copy added in v1.0.1003

func Copy(path string, target string) error

文件复制

func CopyDirectory added in v1.0.1003

func CopyDirectory(directory string, destination string) error

复制文件夹

func Create added in v1.0.1003

func Create(name string) (*os.File, error)

创建

func Delete added in v1.0.1003

func Delete(path string) error

删除

func DeleteDirectories added in v1.0.1003

func DeleteDirectories(directory string) bool

删除文件夹

func DeleteDirectory added in v1.0.1003

func DeleteDirectory(directory string, preserve ...bool) error

删除文件夹

func Directories added in v1.0.1003

func Directories(directory string) ([]string, error)

列出文件夹

func Dirname added in v1.0.1003

func Dirname(path string) string

获取文件夹名称

func EnsureDirectoryExists added in v1.0.1003

func EnsureDirectoryExists(
	directory string,
	mode uint32,
	recursive ...bool,
) error

创建文件夹

func EvalSymlinks(path string) (string, error)

读取软链接的原始地址

func Exists added in v1.0.1003

func Exists(path string) bool

判断

func Extension added in v1.0.1003

func Extension(path string) string

后缀

func Files added in v1.0.1003

func Files(directory string) ([]string, error)

列出文件

func FormatSize added in v1.0.1005

func FormatSize(size int64) string

格式化数据大小

func FromSlash added in v1.0.1003

func FromSlash(s string) string

将 path 中的 ‘/’ 转换为系统相关的路径分隔符

func Get added in v1.0.1003

func Get(path string, lock ...bool) (string, error)

获取数据

func GetMimeExtension added in v1.0.1007

func GetMimeExtension(mime string) string

获取格式对应的后缀

func GetMimeType

func GetMimeType(extension string) string

获取后缀对应的格式

func Glob added in v1.0.1003

func Glob(pattern string) ([]string, error)

查询

func GuessExtension added in v1.0.1003

func GuessExtension(path string) string

后缀

func Hash added in v1.0.1003

func Hash(path string) (string, error)

md5 值

func IsAbs added in v1.0.1003

func IsAbs(path string) bool

返回路径是否是一个绝对路径

func IsDirectory added in v1.0.1003

func IsDirectory(path string) bool

是否为文件夹

func IsFile added in v1.0.1003

func IsFile(path string) bool

是否是文件

func IsReadable added in v1.0.1003

func IsReadable(path string) bool

是否可读

func IsSymlink(m os.FileMode) bool

是否为软链接

func IsWritable added in v1.0.1003

func IsWritable(path string) bool

是否可写

func Join added in v1.0.1003

func Join(elem ...string) string

将函数可以将任意数量的路径元素放入一个单一路径里,会根据需要添加路径分隔符

func LastModified added in v1.0.1003

func LastModified(path string) int64

文件最后更新时间

func Lines added in v1.0.1003

func Lines(path string) ([]string, error)

行读取

func Link(target string, link string) error

设置软链接

func MakeDirectory added in v1.0.1003

func MakeDirectory(
	directory string,
	mode uint32,
	recursive ...bool,
) error

创建文件夹

func Match added in v1.0.1003

func Match(pattern, name string) (bool, error)

文件路径匹配

func MimeType added in v1.0.1003

func MimeType(path string) string

MimeType

func Missing added in v1.0.1003

func Missing(path string) bool

判断

func Move added in v1.0.1003

func Move(path string, target string) error

移动

func MoveDirectory added in v1.0.1003

func MoveDirectory(
	from string,
	to string,
	overwrite ...bool,
) error

移动文件夹

func Name added in v1.0.1003

func Name(path string) string

文件名称

func Perm added in v1.0.1003

func Perm(path string) (uint32, error)

获取权限

func PermIntString added in v1.0.1007

func PermIntString(path string) (string, error)

权限数字转为字符

func PermString added in v1.0.1003

func PermString(path string) (string, error)

获取权限 - 字符

func Prepend added in v1.0.1003

func Prepend(path string, data string) error

文件头添加

func Put added in v1.0.1003

func Put(path string, contents string, lock ...bool) error

添加数据

func Readlink(path string) (string, error)

读取软链接于原始路径的相对地址

func Realpath added in v1.0.1003

func Realpath(path string) (string, error)

绝对路径

func Rel added in v1.0.1003

func Rel(basepath, targpath string) (string, error)

返回一个相对路径

func Rename added in v1.0.1007

func Rename(path string, target string) error

重命名

func Replace added in v1.0.1003

func Replace(path string, contents string) error

替换

func ReplaceInFile added in v1.0.1003

func ReplaceInFile(search string, replace string, path string) error

替换

func SharedGet added in v1.0.1003

func SharedGet(path string) (string, error)

获取数据

func Size added in v1.0.1003

func Size(path string) int64

文件大小

func Split added in v1.0.1003

func Split(path string) (string, string)

函数根据最后一个路径分隔符将路径 path 分隔为目录和文件名两部分(dir 和 file)

func SplitList added in v1.0.1003

func SplitList(path string) []string

分割 PATH 或 GOPATH 之类的环境变量

func ToSlash added in v1.0.1003

func ToSlash(s string) string

将 path 中平台相关的路径分隔符转换为 ‘/’

func Touch added in v1.0.1003

func Touch(filename string) error

创建文件

func Type added in v1.0.1003

func Type(path string) string

类型,大类

Types

type FileInfo

type FileInfo = os.FileInfo

文件信息

type FileMode

type FileMode = os.FileMode

文件权限

type Filesystem

type Filesystem struct{}

*

  • 本地文件管理器 *
  • @create 2022-2-27
  • @author deatil

func New

func New() *Filesystem

构造函数

func (*Filesystem) Abs

func (this *Filesystem) Abs(path string) (string, error)

返回 path 代表的绝对路径

func (*Filesystem) AllFiles

func (this *Filesystem) AllFiles(directory string) ([]string, error)

全部文件

func (*Filesystem) Append

func (this *Filesystem) Append(path string, data string) error

尾部添加

func (*Filesystem) Basename

func (this *Filesystem) Basename(path string) string

文件目录名称

func (*Filesystem) Chmod

func (this *Filesystem) Chmod(path string, mode uint32) error

设置权限

func (*Filesystem) Clean

func (this *Filesystem) Clean(path string) string

规整化路径

func (*Filesystem) CleanDirectory

func (this *Filesystem) CleanDirectory(directory string) error

清空文件夹

func (*Filesystem) Close

func (this *Filesystem) Close(fd *os.File) error

关闭

func (*Filesystem) Copy

func (this *Filesystem) Copy(path string, target string) error

文件复制

func (*Filesystem) CopyDirectory

func (this *Filesystem) CopyDirectory(directory string, destination string) error

复制文件夹

func (*Filesystem) Create

func (this *Filesystem) Create(name string) (*os.File, error)

创建

func (*Filesystem) Delete

func (this *Filesystem) Delete(path string) error

删除

func (*Filesystem) DeleteDirectories

func (this *Filesystem) DeleteDirectories(directory string) bool

删除文件夹

func (*Filesystem) DeleteDirectory

func (this *Filesystem) DeleteDirectory(directory string, preserve ...bool) error

删除文件夹

func (*Filesystem) Directories

func (this *Filesystem) Directories(directory string) ([]string, error)

列出文件夹

func (*Filesystem) Dirname

func (this *Filesystem) Dirname(path string) string

获取文件夹名称

func (*Filesystem) EnsureDirectoryExists

func (this *Filesystem) EnsureDirectoryExists(
	directory string,
	mode uint32,
	recursive ...bool,
) error

创建文件夹

func (this *Filesystem) EvalSymlinks(path string) (string, error)

读取软链接的原始地址

func (*Filesystem) Exists

func (this *Filesystem) Exists(path string) bool

判断

func (*Filesystem) Extension

func (this *Filesystem) Extension(path string) string

后缀

func (*Filesystem) Files

func (this *Filesystem) Files(directory string) ([]string, error)

列出文件

func (*Filesystem) FromSlash

func (this *Filesystem) FromSlash(s string) string

将 path 中的 ‘/’ 转换为系统相关的路径分隔符

func (*Filesystem) Get

func (this *Filesystem) Get(path string, lock ...bool) (string, error)

获取数据

func (*Filesystem) Glob

func (this *Filesystem) Glob(pattern string) ([]string, error)

查询

func (*Filesystem) GuessExtension

func (this *Filesystem) GuessExtension(path string) string

后缀

func (*Filesystem) Hash

func (this *Filesystem) Hash(path string) (string, error)

md5 值

func (*Filesystem) IsAbs

func (this *Filesystem) IsAbs(path string) bool

返回路径是否是一个绝对路径

func (*Filesystem) IsDirectory

func (this *Filesystem) IsDirectory(path string) bool

是否为文件夹

func (*Filesystem) IsFile

func (this *Filesystem) IsFile(path string) bool

是否是文件

func (*Filesystem) IsReadable

func (this *Filesystem) IsReadable(path string) bool

是否可读

func (this *Filesystem) IsSymlink(m os.FileMode) bool

是否为软链接

func (*Filesystem) IsWritable

func (this *Filesystem) IsWritable(path string) bool

是否可写

func (*Filesystem) Join

func (this *Filesystem) Join(elem ...string) string

函数可以将任意数量的路径元素放入一个单一路径里,会根据需要添加路径分隔符

func (*Filesystem) LastModified

func (this *Filesystem) LastModified(path string) int64

文件最后更新时间

func (*Filesystem) Lines

func (this *Filesystem) Lines(path string) ([]string, error)

行读取

func (this *Filesystem) Link(target string, link string) error

设置软链接

func (*Filesystem) MakeDirectory

func (this *Filesystem) MakeDirectory(
	directory string,
	mode uint32,
	recursive ...bool,
) error

创建文件夹

func (*Filesystem) Match

func (this *Filesystem) Match(pattern, name string) (bool, error)

文件路径匹配

func (*Filesystem) MimeType

func (this *Filesystem) MimeType(path string) string

MimeType

func (*Filesystem) Missing

func (this *Filesystem) Missing(path string) bool

判断

func (*Filesystem) Move

func (this *Filesystem) Move(path string, target string) error

移动

func (*Filesystem) MoveDirectory

func (this *Filesystem) MoveDirectory(
	from string,
	to string,
	overwrite ...bool,
) error

移动文件夹

func (*Filesystem) Name

func (this *Filesystem) Name(path string) string

文件名称

func (*Filesystem) Perm

func (this *Filesystem) Perm(path string) (uint32, error)

获取权限

func (*Filesystem) PermIntString added in v1.0.1007

func (this *Filesystem) PermIntString(path string) (string, error)

权限数字转为字符

func (*Filesystem) PermString

func (this *Filesystem) PermString(path string) (string, error)

获取权限 - 字符

func (*Filesystem) Prepend

func (this *Filesystem) Prepend(path string, data string) error

文件头添加

func (*Filesystem) Put

func (this *Filesystem) Put(path string, contents string, lock ...bool) error

添加数据

func (this *Filesystem) Readlink(path string) (string, error)

读取软链接于原始路径的相对地址

func (*Filesystem) Realpath

func (this *Filesystem) Realpath(path string) (string, error)

绝对路径

func (*Filesystem) Rel

func (this *Filesystem) Rel(basepath, targpath string) (string, error)

返回一个相对路径

func (*Filesystem) Rename added in v1.0.1007

func (this *Filesystem) Rename(path string, target string) error

重命名

func (*Filesystem) Replace

func (this *Filesystem) Replace(path string, contents string) error

替换

func (*Filesystem) ReplaceInFile

func (this *Filesystem) ReplaceInFile(search string, replace string, path string) error

替换

func (*Filesystem) SharedGet

func (this *Filesystem) SharedGet(path string) (string, error)

获取数据

func (*Filesystem) Size

func (this *Filesystem) Size(path string) int64

文件大小

func (*Filesystem) Split

func (this *Filesystem) Split(path string) (string, string)

函数根据最后一个路径分隔符将路径 path 分隔为目录和文件名两部分(dir 和 file)

func (*Filesystem) SplitList

func (this *Filesystem) SplitList(path string) []string

分割 PATH 或 GOPATH 之类的环境变量

func (*Filesystem) ToSlash

func (this *Filesystem) ToSlash(s string) string

将 path 中平台相关的路径分隔符转换为 ‘/’

func (*Filesystem) Touch

func (this *Filesystem) Touch(filename string) error

创建文件

func (*Filesystem) Type

func (this *Filesystem) Type(path string) string

类型,大类

Jump to

Keyboard shortcuts

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