filefriend

package module
v0.0.0-...-343e789 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 6 Imported by: 0

README

filefriend

Documentation Go Report Card



📂 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.

Installation & how to use

To use this package in your own code, make sure your GO_PATH environment variable is correctly set, and install it using go get:

go get github.com/sanderhelleso/filefriend

Then, you can include it in your project:

import "github.com/sanderhelleso/filefriend"

Alternatively, you can clone it yourself:

git clone https://github.com/sanderhelleso/filefriend.git

Documentation

Detailed documentation and overview of the package can be found here

Licence

MIT

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(name string, ext string, folder string, content string, amount int) error

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

func CreateFolder(path string) error

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

func FilenameWithoutExt(file string) string

FilenameWithoutExt returns the cleaned filename without the folderpath or extension.

func FullAbsPath

func FullAbsPath(file string) (string, error)

FullAbsPath returns the full absolute path from the passed in file or potensial error that occurred.

func GetChangedTime

func GetChangedTime(file string) (string, error)

GetChangedTime returns the timestamp of the passed in file's last modified time, or potensial error that occurred.

func GetSize

func GetSize(file string) (string, error)

GetSize returns the size of the passed in file or potensial error that occurred.

func IsFolder

func IsFolder(path string) (bool, error)

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

func Move(from string, to string) error

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

func MoveFiles(files []*File, dest string, cleanup bool) error

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

func PathExists(path string) bool

PathExists checks if a given path exists or not. Returns a boolean (true/false) depending on case.

func RenameFiles

func RenameFiles(files []*File, newName string) error

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

func SanitizePath(path string) string

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

func GetFileInfo(file string) (*File, error)

GetFileInfo retrieves the stats & information about a specific file. Returns a pointer to the file or potensial error that occurred.

func ScanFolder

func ScanFolder(folder string, pattern string, recur bool) ([]*File, error)

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

Jump to

Keyboard shortcuts

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