filepath_plus

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: Apache-2.0 Imports: 14 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateEmptyFilePathExisted = errors.New("create empty file path is existed")

Functions

func AlterFile

func AlterFile(path string, data []byte) error

AlterFile

alter file
@param path string
@param data []byte

this method will keep file mode if file not exist, will not create file and return error

func AlterFileWithString

func AlterFileWithString(path string, content string, fileMod fs.FileMode) error

AlterFileWithString

check or file with content, if file exist, will coverage
@param path string
@param content string
@param fileMod os.FileMode(0o666) os.FileMode(0o644)

func AlterFileWithStringFast

func AlterFileWithStringFast(path string, content string) error

AlterFileWithStringFast

check or file with content, if file exist, will coverage
crate folder of file with os.FileMode(0o666)
@param path string
@param content string

func AppendFileHead

func AppendFileHead(path string, content []byte) error

AppendFileHead

append file head
@param path string
@param content []byte

this method will keep file mode if file not exist, will not create file and return error

func AppendFileTail

func AppendFileTail(path string, content []byte) error

AppendFileTail

append file tail
@param path string
@param content []byte

this method will keep file mode if file not exist, will not create file and return error

func CheckOrCreateFileWithString

func CheckOrCreateFileWithString(path string, content string, fileMod fs.FileMode) error

CheckOrCreateFileWithString

check or create file with content, if file exist, will not coverage
@param path string
@param content string
@param fileMod os.FileMode(0o666) os.FileMode(0o644)

func CheckOrCreateFileWithStringFast

func CheckOrCreateFileWithStringFast(path string, context string) error

CheckOrCreateFileWithStringFast

check or create file with content, if file exist, will not coverage
crate folder of file with os.FileMode(0o666)
@param path string
@param content string

func CopyFile added in v1.8.0

func CopyFile(
	sourcePath string,
	target string,
	perm os.FileMode,
	coverage bool,
) error

CopyFile

sourcePath is the path to the file in the embedded filesystem.
target is the target path where the file will be copied.
perm is the permission mode of the target file. os.FileMode(0o644) or os.FileMode(0o666)
coverage true will coverage old

func CreateEmptyFile added in v1.9.0

func CreateEmptyFile(path string, perm os.FileMode) error

CreateEmptyFile

path is the target path where the file crate.
perm is the permission mode of the target file. os.FileMode(0o644) or os.FileMode(0o666)

if path is exist, will return CreateEmptyFilePathExisted.

func FetchDefaultFolderFileMode added in v1.7.1

func FetchDefaultFolderFileMode() fs.FileMode

FetchDefaultFolderFileMode if in windows, will return os.FileMode(0o766), windows not support umask

use umask to get folder file mode

if not windows, will use umask, will return os.FileMode(0o777) - umask not support umask will use os.FileMode(0o777).

func Mkdir

func Mkdir(path string) error

Mkdir will use FetchDefaultFolderFileMode().

func PathExists

func PathExists(path string) (bool, error)

PathExists

path exists

func PathExistsFast

func PathExistsFast(path string) bool

PathExistsFast

path exists fast

func PathIsDir

func PathIsDir(path string) bool

PathIsDir

path is dir

func ReadFileAsByte

func ReadFileAsByte(path string) ([]byte, error)

ReadFileAsByte

read file as byte array

func ReadFileAsJson added in v1.1.1

func ReadFileAsJson(path string, v interface{}) error

ReadFileAsJson

read file as json

func ReadFileAsLines added in v1.3.0

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

ReadFileAsLines

read file as lines, this method will read all line, so if file is too big, will be slow.

func ReplaceFileLineByLine added in v1.4.0

func ReplaceFileLineByLine(path string, reg string, index int, replace string) error

ReplaceFileLineByLine

read file as lines, this method will read all line, so if file is too big, will be slow

func RmDir

func RmDir(path string, force bool) error

RmDir

remove dir by path

func WriteFileAsJson added in v1.1.1

func WriteFileAsJson(path string, v interface{}, fileMod fs.FileMode, coverage, beauty bool) error

WriteFileAsJson write json file

path most use Abs Path
v data
fileMod os.FileMode(0o666) or os.FileMode(0o644)
coverage true will coverage old
beauty will format json when write

func WriteFileAsJsonBeauty added in v1.1.1

func WriteFileAsJsonBeauty(path string, v interface{}, coverage bool) error

WriteFileAsJsonBeauty

write json file as 0666 and beauty

func WriteFileByByte

func WriteFileByByte(path string, data []byte, fileMod fs.FileMode, coverage bool) error

WriteFileByByte

write bytes to file
path most use Abs Path
data []byte
fileMod os.FileMode(0o666) os.FileMode(0o644)
coverage true will coverage old

Types

This section is empty.

Jump to

Keyboard shortcuts

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