Documentation ¶
Overview ¶
Package files implements file utility functions.
Index ¶
- func Abs(path string) (string, error)
- func AbsDir(file string) (string, error)
- func Copy(dstfile string, srcfile string, perm os.FileMode) error
- func Create(name string) (*os.File, error)
- func CurrentDir() (string, error)
- func Dir(file string) string
- func Extension(fileName string) string
- func IsExist(filename string) bool
- func Join(elem ...string) string
- func LookPath(file string) (string, error)
- func Mkdir(name string, perm os.FileMode) error
- func MkdirAll(name string, perm os.FileMode) error
- func ModTime(file string) (out time.Time, err error)
- func ModTimeUnix(file string) (int64, error)
- func Read(filename string) (string, error)
- func Remove(name string) error
- func Rename(oldname, newname string) error
- func SetPriority(value int)
- func Size(file string) (int64, error)
- func Unzip(zipFile, destDir string) error
- func Upload(w http.ResponseWriter, r *http.Request, field, confdir, filedir string) (out string, err error)
- func Uploads(w http.ResponseWriter, r *http.Request, field, confdir, filedir string) (out []string, err error)
- func Write(filename string, data string, perm os.FileMode) error
- func Zip(files []*os.File, dest string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func AbsDir ¶
Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func Create ¶
Create creates the named file mode 0666 (before umask), truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.
func CurrentDir ¶
func Dir ¶
Dir returns all but the last element of path, typically the path's directory. After dropping the final element, Dir calls Clean on the path and trailing slashes are removed. If the path is empty, Dir returns ".". If the path consists entirely of separators, Dir returns a single separator. The returned path does not end in a separator unless it is the root directory.
func Extension ¶
Extension returns the <a href="http://en.wikipedia.org/wiki/Filename_extension">file extension</a> for the given file name, or the empty string if the file has no extension. The result does not include the '{@code .}'.
func IsExist ¶
IsExist reports whether the specified file exists. Returns true if the file exists, false if it does not exist.
Example ¶
package main import ( "fmt" "gopkg.in/goyy/goyy.v0/util/files" ) func main() { fmt.Println(files.IsExist("./example.txt")) fmt.Println(files.IsExist("./README")) }
Output: true false
func Join ¶
Join joins any number of path elements into a single path, adding a Separator if necessary. Join calls Clean on the result; in particular, all empty strings are ignored. On Windows, the result is a UNC path if and only if the first path element is a UNC path.
func LookPath ¶
LookPath searches for an executable binary named file in the directories named by the PATH environment variable. If file contains a slash, it is tried directly and the PATH is not consulted. The result may be an absolute path or a path relative to the current directory.
func Mkdir ¶
Mkdir creates a new directory with the specified name and permission bits. If there is an error, it will be of type *PathError.
func MkdirAll ¶
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func ModTimeUnix ¶
ModTimeUnix returns the file modification time
func Read ¶
Read reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because Read reads the whole file, it does not treat an EOF from Read as an error to be reported.
Example ¶
package main import ( "fmt" "gopkg.in/goyy/goyy.v0/util/files" ) func main() { s, _ := files.Read("./example.txt") fmt.Println(s) }
Output: Hello world!
func Remove ¶
Remove removes the named file or directory. If there is an error, it will be of type *PathError.
func Rename ¶
Rename renames (moves) oldpath to newpath. If newpath already exists, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. If there is an error, it will be of type *LinkError.
func Upload ¶
func Upload(w http.ResponseWriter, r *http.Request, field, confdir, filedir string) (out string, err error)
Upload uploads a file. eg. confdir : /assets filedir : /upl field : art/library out : /assets/upl/art/library/8826e07b8d2111e6ab7854e873b1560c.png
func Uploads ¶
func Uploads(w http.ResponseWriter, r *http.Request, field, confdir, filedir string) (out []string, err error)
Uploads uploads a multipart file. eg. confdir : /assets filedir : /upl field : art/library out : /assets/upl/art/library/8826e07b8d2111e6ab7854e873b1560c.png
func Write ¶
Write writes data to a file named by filename. If the file does not exist, Write creates it with permissions perm; otherwise Write truncates it before writing.
Example ¶
package main import ( "fmt" "log" "gopkg.in/goyy/goyy.v0/util/files" ) func main() { filename := "./example.txt" data := "Hello goyy!" if err := files.Write(filename, data, 0755); err != nil { log.Fatalf("Write %s: %v", filename, err) } s, _ := files.Read(filename) fmt.Println(s) files.Write(filename, "Hello world!", 0755) // recover }
Output: Hello goyy!
Types ¶
This section is empty.