fileutil

package module
v0.0.0-...-efd73b5 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 2 Imported by: 4

README

codecov Build Status go.dev Go Report Card Licenses

fileutil

golang file utils for common use

Basic Usage

Installation

To get the package, execute:

go get github.com/gofika/fileutil
Example
package main

import (
	"fmt"
	"github.com/gofika/fileutil"
)

func main() {
	name := "foo/bar.txt"
	data := []byte("Hello")
	// write data to file. will create dir: foo
	err := fileutil.WriteFile(name, data)
	if err != nil {
		fmt.Printf("Write file failed. err: %s\n", err.Error())
		return
	}
	// check file exist
	if !fileutil.IsExist(name) {
		fmt.Printf("file %s not exist.\n", name)
		return
	}
	// clear temp file
	fileutil.DeleteAll("foo")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentDir

func CurrentDir() (currentDir string)

CurrentDir return the directory where the program is located.

func Delete

func Delete(name string)

Delete removes the named file or directory. not mind for error

func DeleteAll

func DeleteAll(path string)

DeleteAll removes path and any children it contains. not mind for error

func EnsureDirExists

func EnsureDirExists(path string)

EnsureDirExists create all directory if not exists Example:

EnsureDirExists("/foo/bar/baz.js") // the following directory will be created: /foo/bar/
EnsureDirExists("/foo/bar/baz/") // the following directory will be created: /foo/bar/baz/

func EnsureFileWritable

func EnsureFileWritable(filename string)

EnsureFileWritable make file writable if not

func IsExist

func IsExist(filename string) bool

IsExist return true if file exists

func IsWritable

func IsWritable(filename string) bool

IsWritable return true if file is writable

func OpenWrite

func OpenWrite(filename string) (*os.File, error)

OpenWrite open file for write. if the file doesn't exist, create it

func WriteFile

func WriteFile(filename string, data []byte) (err error)

WriteFile write bytes to file. will create all path dir if not exists

Types

This section is empty.

Jump to

Keyboard shortcuts

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