README ¶
fileutil
Provides utilities for interacting with files on the filesystem, such as determining if a file is Binary or a Symlink.
IsBinaryFile
Attempts to determine if the provided file is Binary by reading pieces of it from the filesystem.
IsSymlink
Determines if the file is a Symlink
IsDir
Determines if the file is a directory or regular file.
DirToArray
Collapses a directory tree into a slice of files, including the full path to the file. File filters and Directory filters can be supplied to limit the results, such as file filters that remove Binary or Symlink files from the results. The default file filter exclused symlinks and binary files, and the default directory filter excludes a .git directory. These can be supplied to fit your needs.
files := fileutil.DirToArray(dir, false, fileutil.SymlinkFileFilter, fileutil.DefaultDirectoryFilter)
FilterExtBlacklist
FilterExtBlacklist takes a list of extensions and a slice of files and removes any files in that list that have an extension matching an item in the blacklist.
FilterExtWhitelist
FilterExtWhitelist takes a list of extensions and a slice of files and removes any files in that list that do not have an extension matching an item in the whitelist.
Documentation ¶
Index ¶
- func BinaryFileFilter(path, fileName string) bool
- func DefaultDirectoryFilter(path, dirName string) bool
- func DefaultFileFilter(path, fileName string) bool
- func DirToArray(dir string, followSyms bool, fileFilter func(string, string) bool, ...) []string
- func FilterExtBlacklist(ext, files []string) []string
- func FilterExtWhitelist(ext, files []string) []string
- func FilterOutBinaries(files []string) []string
- func FilterOutSymlinks(files []string) []string
- func IsBinaryData(b []byte) bool
- func IsBinaryFile(fileName string) bool
- func IsDir(fileName string) bool
- func IsFile(fileName string) bool
- func IsSymlink(fileName string) bool
- func SymlinkFileFilter(path, fileName string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinaryFileFilter ¶
BinaryFileFilter excludes binary files.
func DefaultDirectoryFilter ¶
DefaultDirectoryFilter returns true if the file should be kept, false if it should be discarded.
func DefaultFileFilter ¶
DefaultFileFilter excludes symlinks and binary files.
func DirToArray ¶
func DirToArray(dir string, followSyms bool, fileFilter func(string, string) bool, dirFilter func(string, string) bool) []string
DirToArray will flatten a directory into a simple list of files that can be iterated over.
func FilterExtBlacklist ¶
FilterExtBlacklist removes any files where the extension is found in the extension list.
func FilterExtWhitelist ¶
FilterExtWhitelist removes any files where the extension is not found in the extension list.
func FilterOutBinaries ¶
FilterOutBinaries removes any binary files from the given file list.
func FilterOutSymlinks ¶
FilterOutSymlinks removes any symlink files from the given file list.
func IsBinaryData ¶
IsBinaryData attemtpts to determine whether a given byte slice contains binary data.
func IsBinaryFile ¶
IsBinaryFile attemtpts to determine whether a file is a binary file.
func SymlinkFileFilter ¶
SymlinkFileFilter excludes symlinks and binary files.
Types ¶
This section is empty.