shutil

package module
v0.0.0-...-49b0218 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: MIT Imports: 9 Imported by: 0

README

shutil [仅适用于Linux]

English

shutil——Pythonshutil-PyDoc的Golang克隆迁移,提供了文件以及文件集合的高阶操作。 特别是提供了支持文件复制和删除的函数。相对于原Python的shutil,更添加了些许符合名称的功能函数。(shutil是shell utilities的缩写,意即shell工具包)

功能函数列表:

目录与文件操作

  • CopyFileObj(fSrc,fDst,length):拷贝/复制文件对象
  • CopyFile(src,dst,followSymlinks bool):拷贝/复制文件
  • CopyMode(src,dst,followSymlinks bool)
  • CopyStat(src,dst,followSymlinks bool)
  • Copy(src,dst,followSymlinks bool)
  • Copy2(src,dst,followSymlinks bool)
  • IgnorePatterns(...patterns)
  • CopyTree(src, dst, symlinks=False, ignore=None, copy_function=copy2, ignore_dangling_symlinks=False, dirs_exist_ok=False)
  • RmTree(path, ignore_errors=False, onerror=None):移除/删除 目录
  • Move(src, dst, copy_function=copy2):移动/剪切
  • DiskUsage(path):获取磁盘使用情况
  • Chown(path, user=None, group=None):更改某个目录的主人
  • Which(cmd, mode=os.F_OK | os.X_OK, path=None):查询某个命令的程序所在路径

文件包操作

  • MakeArchive(base_name, format[, root_dir[, base_dir[, verbose[, dry_run[, owner[, group[, logger]]]]]]]):打包文件
  • GetArchiveFormats():获取文件包格式
  • RegisterArchiveFormat(name, function[, extra_args[, description]]):注册文件包格式
  • UnregisterArchiveFormat(name):注销文件包格式
  • UnpackArchive(filename[, extract_dir[, format]]):解包文件包
  • RegisterUnpackFormat(name, extensions, function[, extra_args[, description]])
  • UnregisterUnpackFormat(name)
  • GetUnpackFormats():获取解包格式

查询终端输出尺寸

  • GetTerminalSize(fallback=(columns, lines)):获取终端(terminal)尺寸

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chown

func Chown(path string, user, group uint) (err error)

Chown Change owner user and/or group of the given path.

func Copy

func Copy(src, dst string, followSymlinks ...bool) (err error)

Copy Copies the file src to the file or directory dst.

func Copy2

func Copy2(src, dst string, followSymlinks ...bool) (err error)

Copy2 Copies the file src to the file or directory dst. also attempts to preserve file metadata

func CopyFile

func CopyFile(src, dst string, followSymlinks ...bool) (err error)

CopyFile Copy the contents (no metadata) of the file named src to a file named dst and return dst in the most efficient way possible.

func CopyFileObj

func CopyFileObj(fsrc, fdst *os.File, length ...int64) (err error)

CopyFileObj Copy the contents of the file-like object fsrc to the file-like object fdst.

func CopyMode

func CopyMode(src, dst string, followSymlinks ...bool) (err error)

CopyMode Copy the permission bits from src to dst.

func CopyStat

func CopyStat(src, dst string, followSymlinks ...bool) (err error)

CopyStat Copy the permission bits, last access time, last modification time, and flags from src to dst.

func CopyTree

func CopyTree() (err error)

CopyTree Recursively copy an entire directory tree rooted at src to a directory named dst and return the destination directory.

func CopyTreeWithOpt

func CopyTreeWithOpt() (err error)

CopyTreeWithOpt same to copytree,but can add extra opt-config

func GetTerminalSize

func GetTerminalSize(fallback ...winsize) (c, l int, err error)

GetTerminalSize Get the size of the terminal window.

func IgnorePatterns

func IgnorePatterns(patterns ...string)

IgnorePatterns A factory function creates a function that can be used as a callable for copytree()’s ignore argument

func MakeArchive

func MakeArchive(opt *MakeOpt) (err error)

MakeArchive Create an archive file (such as zip or tar) and return its name.

func Move

func Move(srt, dst string) (err error)

Move Recursively move a file or directory (src) to another location (dst) and return the destination.

func RegisterArchiveFormat

func RegisterArchiveFormat(name string, f func()) (err error)

RegisterArchiveFormat Register an archiver for the format name.

func RegisterUnpackFormat

func RegisterUnpackFormat(name string, f func()) (err error)

RegisterUnpackFormat Registers an unpack format.

func RemoveDirContents

func RemoveDirContents(dir string, p ...string) (err error)

func RmTree

func RmTree(dir string) (err error)

RmTree Delete an entire directory tree; path must point to a directory (but not a symbolic link to a directory).

func UnRegisterArchiveFormat

func UnRegisterArchiveFormat(name string) (err error)

UnRegisterArchiveFormat Remove the archive format name from the list of supported formats.

func UnRegisterUnpackFormat

func UnRegisterUnpackFormat(name string) (err error)

UnRegisterUnpackFormat Unregister an unpack format. name is the name of the format.

func UnpackArchive

func UnpackArchive(opt *UnpackOpt)

UnpackArchive Unpack an archive. filename is the full path of the archive.

func Which

func Which(cmd string, mode uint, path ...string) (p string, err error)

Which Return the path to an executable which would be run if the given cmd was called.

Types

type ArchiveFormat

type ArchiveFormat struct {
	Name  string
	Sufix []string
	Desc  string
}

ArchiveFormat obj

func GetArchiveFormats

func GetArchiveFormats() (afs []*ArchiveFormat)

GetArchiveFormats Return a list of supported formats for archiving

func GetUnpackFormats

func GetUnpackFormats() (afs []*ArchiveFormat)

GetUnpackFormats Return a list of all registered formats for unpacking.

func (ArchiveFormat) String

func (af ArchiveFormat) String() string

type Diskusage

type Diskusage struct {
	Total     uint64  //  total size of the file system
	Used      uint64  //  total bytes used in file system
	Free      uint64  // total free bytes on file system
	Available uint64  // total available bytes on file system to an unprivileged user
	Usage     float32 //percentage of use on the file system
}

func DiskUsage

func DiskUsage(path string) (usage Diskusage, err error)

DiskUsage Return disk usage statistics about the given path

func (Diskusage) ToHuman

func (du Diskusage) ToHuman(unit ...string) DiskusageHuman

type DiskusageHuman

type DiskusageHuman struct {
	Total     string //  total size of the file system
	Used      string //  total bytes used in file system
	Free      string // total free bytes on file system
	Available string // total available bytes on file system to an unprivileged user
	Usage     string //percentage of use on the file system
}

type Error

type Error struct {
	Err error
}

Error shutil base error

type ExecError

type ExecError struct {
	Error
}

ExecError Raised when a command could not be executed

type MakeOpt

type MakeOpt struct {
	Name    string
	Format  string
	RootDir string
	BaseDir string
	Verbose bool
	DryRun  bool
	Owner   int64
	Group   int64
	Logger  string
}

MakeOpt obj

type ReadError

type ReadError struct {
	Error
}

ReadError Raised when an archive cannot be read

type RegistryError

type RegistryError struct {
	Error
}

RegistryError Raised when a registry operation with the archiving and unpacking registries fails

type SameFileError

type SameFileError struct {
	Error
}

SameFileError Raised when source and destination are the same file.

type SpecialFileError

type SpecialFileError struct {
	Error
}

SpecialFileError Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)

type UnpackOpt

type UnpackOpt struct {
	Filename   string
	ExtractDir string
	Format     string
}

UnpackOpt obj

Jump to

Keyboard shortcuts

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