Documentation ¶
Overview ¶
Package filefriend is a convenient wrapper around the os/filepath module for Go. Provides a wide variety of functions that combines packages into one, single wrapper, allowing for flexible and easy modifications of the systems file and folders.
Index ¶
- func Create(name string, ext string, folder string, content string, amount int) error
- func CreateFolder(path string) error
- func FilenameWithoutExt(file string) string
- func FullAbsPath(file string) (string, error)
- func GetChangedTime(file string) (string, error)
- func GetSize(file string) (string, error)
- func IsFolder(path string) (bool, error)
- func Move(from string, to string) error
- func MoveFiles(files []*File, dest string, cleanup bool) error
- func PathExists(path string) bool
- func RenameFiles(files []*File, newName string) error
- func SanitizePath(path string) string
- type File
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Create creates 'n' amount of files, with extension, to passed in folder, with passed in content, that will be written to each single file.
If file in folder exists, Create will skip to avoid remake of the file. Returns an error or nil depending on successful write or fail.
func CreateFolder ¶
CreateFolder creates a new folder at a given path. If the folder does not exist create it. Returns an error if the creation failed.
func FilenameWithoutExt ¶
FilenameWithoutExt returns the cleaned filename without the folderpath or extension.
func FullAbsPath ¶
FullAbsPath returns the full absolute path from the passed in file or potensial error that occurred.
func GetChangedTime ¶
GetChangedTime returns the timestamp of the passed in file's last modified time, or potensial error that occurred.
func IsFolder ¶
IsFolder returns a boolean (true) if the given path is a folder. If the path is a file, return boolean (false) and the error with the reason.
func Move ¶
Move renames and moves the files from one directory, to another depending on folder structure input. Returns error or nil depending on successful move or rename.
func MoveFiles ¶
MoveFiles moves all the files in given slice to destination. Uses the passed in destination parameter to select folder to move to. Cleanup will delete all trailing folders that are empty after move.
Returns the updated slice containing, all the files or potensial error that occurred.
func PathExists ¶
PathExists checks if a given path exists or not. Returns a boolean (true/false) depending on case.
func RenameFiles ¶
RenameFiles renames all the files in given slice to newName. newName defines a string, passed in as param, that will replace the name of the file.
If slice contains more than 1 file, an index will added at the end of filename. Returns the updated slice, containing all the files with the new name or potensial error.
func SanitizePath ¶
SanitizePath formats the path into system navigatable format. If the path is invalid for system, format the path with starting './' and trailing '/'
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represent a file in a folder. Containing useful stats and information about the file.
name: The name of the file without extension or path.
extension: The extension of the file.
folder: The relative folder path of the file.
path: The absolute filesystems path to the folder.
size: The size of the file in bytes in string format.
lastChanged: The files last modified time in string format.
func GetFileInfo ¶
GetFileInfo retrieves the stats & information about a specific file. Returns a pointer to the file or potensial error that occurred.
func ScanFolder ¶
ScanFolder scans the given folder passed in. Recur (true/false) decides if scan will follows nested folders. Pattern matches files to include/exclude:
pattern: { term } term: '*' matches any sequence of non-Separator characters '?' matches any single non-Separator character '[' [ '^' ] { character-range } ']' character class (must be non-empty) c matches character c (c != '*', '?', '\\', '[') '\\' c matches character c character-range: c matches character c (c != '\\', '-', ']') '\\' c matches character c lo '-' hi matches character c for lo <= c <= hi
Returns a slice containing all the files scanned, matching the given pattern, or potensial error that occurred