file

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: Apache-2.0 Imports: 10 Imported by: 7

Documentation

Overview

Copyright (C) 2019 tisnyo <tisnyo@gmail.com>.

package file contains some file operations. license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsPath

func AbsPath(relPath string) (string, error)

AbsPath return the absolute path of a relative path.

func AppendFile

func AppendFile(path string) (*os.File, error)

AppendFile opens a file to append or creates it if it is not exist.

func ChangeWorkDir

func ChangeWorkDir(path string) error

ChangeWorkDir changes the current working directory to the named directory.

func CopyFile

func CopyFile(src string, dest string) (bool, error)

CopyFile copies src file to dest file.

func CopyFileTo

func CopyFileTo(src string, dir string) (bool, error)

CopyFileTo copies a file to target dir.

func Crc32

func Crc32(src string) (string, error)

Crc32 returns file's crc32 string.

func CreateDir

func CreateDir(path string) error

CreateDir creates a new directory.

func CreateDirs

func CreateDirs(path string) error

CreateDirs creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.

func CreateFile

func CreateFile(path string) (*os.File, error)

CreateFile creates a new file, truncating it if it already exists

func Delete

func Delete(path string) bool

Delete deletes a file or directory. special: it returns true if the file not exists.

func DeleteAll

func DeleteAll(path string) bool

DeleteAll deletes file or directory. if it is a directory, it will try to delete all files below. special: it returns true if the file not exists.

func Exists

func Exists(path string) bool

Exists check whether the file exists.

func FixPath

func FixPath(input string) string

FixPath fixed file path in a simple way, examples:

"/aaa/aa\\bb\\cc/d/////"     ->  "/aaa/aa/bb/cc/d"
"E:/aaa/aa\\bb\\cc/d////e/"  ->  "E:/aaa/aa/bb/cc/d/e"
""                           ->  "."
"/"                          ->  "/"

func GetFile

func GetFile(path string) (*os.File, error)

GetFile opens file in readonly mode.

func GetFileExt

func GetFileExt(filePath string) string

GetFileExt returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final slash-separated element of path; it is empty if there is no dot.

func GetFileInfo

func GetFileInfo(path string) (os.FileInfo, error)

GetFileInfo gets the file information.

func GetFileMd5

func GetFileMd5(fi string) (string, error)

GetFileMd5 gets file's md5.

func GetTempDir

func GetTempDir() string

GetTempDir returns the default directory to use for temporary files. On Unix systems, it returns $TMPDIR if non-empty, else /tmp. On Windows, it uses GetTempPath, returning the first non-empty value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory. On Plan 9, it returns /tmp. The directory is neither guaranteed to exist nor have accessible permissions.

func GetWorkDir

func GetWorkDir() (string, error)

GetWorkDir returns a rooted path name corresponding to the current directory. If the current directory can be reached via multiple paths (due to symbolic links), Getwd may return any one of them.

func IsAbsPath

func IsAbsPath(path string) bool

IsAbsPath reports whether the path is absolute.

func IsDir1

func IsDir1(path string) bool

IsDir1 checks whether the path represents a file.

func IsDir2

func IsDir2(file *os.File) bool

IsDir2 checks whether the path represents a file.

func IsFile1

func IsFile1(path string) bool

IsFile1 checks whether the path represents a file.

func IsFile2

func IsFile2(file *os.File) bool

IsFile2 checks whether the file represents a file.

func ListFiles

func ListFiles(path string) ([]os.FileInfo, error)

ListFiles reads the directory named by dirname and returns a list of directory entries sorted by filename.

func MoveFile

func MoveFile(src string, dest string) error

MoveFile renames (moves) oldpath to newpath.

func OpenFile

func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)

OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.) and perm (before umask), if applicable. If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError.

Copy from os.OpenFile.

Types

This section is empty.

Jump to

Keyboard shortcuts

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