Documentation
¶
Index ¶
- Constants
- Variables
- func ConcatDir(src, dst string, filter FilterFile, perm os.FileMode) error
- func ConcatFiles(sources []string, dst string, perm os.FileMode) error
- func CopyDir(src, dst string) error
- func CopyFile(src, dst string) error
- func DeleteDir(path string) error
- func DeleteFile(path string) error
- func FileHash(path, algo string) (string, error)
- func FormatSize(bytes int64) string
- func GetAllExtensions() []string
- func GetFileDescCat(ext string) string
- func GetFileDescName(ext string) string
- func GetMimeType(ext string) string
- func IsFileBinary(ext string) *bool
- func IsFileCompressed(ext string) *bool
- func IsFileExecutable(ext string) *bool
- func MoveDir(src, dst string) error
- func MoveFile(src, dst string) error
- func TarAll(baseFolder, tarfile string) error
- func TarList(tarfile string) ([]string, error)
- func UnTar(tarfile, dest string) error
- func UnZip(zipfile, dest string) error
- func ZipAll(baseFolder, zipfile string) error
- func ZipList(zipfile string) ([]string, error)
- type DirInfo
- type DirStats
- type FileDesc
- type FileInfo
- type FilterDir
- type FilterFile
Constants ¶
const ( CategoryDocument = "Document" CategorySpreadsheet = "Spreadsheet" CategoryPresentation = "Presentation" CategoryImage = "Image" CategoryAudio = "Audio" CategoryVideo = "Video" CategoryArchive = "Archive" CategoryExecutable = "Executable" CategoryCode = "Code" CategoryConfig = "Config" CategoryData = "Data" CategoryDatabase = "Database" CategorySecurity = "Security" CategoryFont = "Font" Category3D = "3D" CategoryEbook = "eBook" CategoryCloud = "Cloud" CategoryAutomation = "Automation" CategoryScientist = "Scientist Data" CategoryDiskImage = "Disk Image" CategoryLog = "Log" CategoryTemp = "Temporary" CategoryOther = "Other" )
const ( // Document. DOC string = "doc" DOCX string = "docx" DOT string = "dot" DOTX string = "dotx" DOTM string = "dotm" ODT string = "odt" OTT string = "ott" PDF string = "pdf" TXT string = "txt" RTF string = "rtf" MD string = "md" OXPS string = "oxps" XPS string = "xps" WP string = "wp" WPD string = "wpd" // Spreadsheets. XLS string = "xls" XLSX string = "xlsx" XLSM string = "xlsm" XLT string = "xlt" XLTX string = "xltx" ODS string = "ods" SXC string = "sxc" CSV string = "csv" TSV string = "tsv" // Presentation. PPT string = "ppt" PPTX string = "pptx" PPTM string = "pptm" POT string = "pot" POTX string = "potx" PPS string = "pps" PPSX string = "ppsx" ODP string = "odp" // Image. JPG string = "jpg" JPEG string = "jpeg" PNG string = "png" GIF string = "gif" BMP string = "bmp" TIFF string = "tiff" TIF string = "tif" SVG string = "svg" WEBP string = "webp" ICO string = "ico" HEIC string = "heic" HEIF string = "heif" RAW string = "raw" CR2 string = "cr2" NEF string = "nef" ARW string = "arw" PSD string = "psd" AI string = "ai" EPS string = "eps" INDD string = "indd" SKETCH string = "sketch" FIGMA string = "fig" // Audio. MP3 string = "mp3" WAV string = "wav" FLAC string = "flac" AAC string = "aac" OGG string = "ogg" WMA string = "wma" M4A string = "m4a" AIFF string = "aiff" ALAC string = "alac" OPUS string = "opus" MID string = "mid" MIDI string = "midi" // Video. MP4 string = "mp4" AVI string = "avi" MKV string = "mkv" MOV string = "mov" WMV string = "wmv" FLV string = "flv" WEBM string = "webm" M4V string = "m4v" MPEG string = "mpeg" MPG string = "mpg" THREEGP string = "3gp" THREEG2 string = "3g2" M2TS string = "m2ts" MTS string = "mts" VOB string = "vob" TS_VIDEO string = "ts_video" // Archive/Compressed. ZIP string = "zip" RAR string = "rar" TAR string = "tar" GZ string = "gz" GZIP string = "gzip" SEVENZ string = "7z" BZ2 string = "bz2" XZ string = "xz" TGZ string = "tgz" TAR_GZ string = "tar.gz" TAR_BZ2 string = "tar.bz2" TAR_XZ string = "tar.xz" ZST string = "zst" LZ4 string = "lz4" LZH string = "lzh" CAB string = "cab" ISO string = "iso" // Executable/System. EXE string = "exe" MSI string = "msi" SHELLSCRIPT string = "sh" BASH string = "bash" ZSH string = "zsh" FISH string = "fish" BAT string = "bat" CMD string = "cmd" PS1 string = "ps1" APP string = "app" DMG string = "dmg" DEB string = "deb" RPM string = "rpm" APPIMAGE string = "appimage" // Code - Web. HTML string = "html" HTM string = "htm" CSS string = "css" SCSS string = "scss" SASS string = "sass" LESS string = "less" JS string = "js" JSX string = "jsx" TS string = "ts" TSX string = "tsx" VUE string = "vue" SVELTE string = "svelte" SLIM string = "slim" ERB string = "erb" // Code - Languages. PY string = "py" PYW string = "pyw" GO string = "go" CPP string = "cpp" CC string = "cc" C string = "c" H string = "h" HH string = "hh" HPP string = "hpp" JAVA string = "java" CLASS string = "class" KT string = "kt" KTS string = "kts" SCALA string = "scala" SWIFT string = "swift" RB string = "rb" RUBY string = "ruby" PHP string = "php" RUST string = "rust" DART string = "dart" LUA string = "lua" PERL string = "pl" PM string = "pm" RMARKDOWN string = "rmd" // Code - Config/Build. JSON string = "json" JSON5 string = "json5" JSONC string = "jsonc" XML string = "xml" YAML string = "yaml" YML string = "yml" TOML string = "toml" INI string = "ini" CONF string = "conf" CONFIG string = "config" ENV string = "env" PROPERTIES string = "properties" PROPS string = "props" GRADLE string = "gradle" GRADLE_KTS string = "gradle.kts" MAKEFILE string = "makefile" CMAKE string = "cmake" LOCK string = "lock" PACKAGE string = "package" HTACCESS string = "htaccess" // Code - Data format. SQL string = "sql" GRAPHQL string = "graphql" GQL string = "gql" MDX string = "mdx" // Database. DB string = "db" SQLITE string = "sqlite" SQLITE3 string = "sqlite3" DB3 string = "db3" // Certificate/Security. PEM string = "pem" CRT string = "crt" CER string = "cer" DER string = "der" KEY string = "key" CSR string = "csr" P12 string = "p12" PFX string = "pfx" P7B string = "p7b" P7C string = "p7c" JKS string = "jks" GPG string = "gpg" PGP string = "pgp" SRL string = "srl" CRL string = "crl" // Font. TTF string = "ttf" OTF string = "otf" WOFF string = "woff" WOFF2 string = "woff2" EOT string = "eot" // 3D/CAD. OBJ string = "obj" FBX string = "fbx" STL string = "stl" DWG string = "dwg" DXF string = "dxf" BLEND string = "blend" MAX3D string = "max" THREEDS string = "3ds" IGES string = "iges" IGS string = "igs" STEP string = "step" STP string = "stp" IPT string = "ipt" IAM string = "iam" SLDDRPRT string = "sldprt" SLDDRASM string = "slddrw" // eBook. EPUB string = "epub" MOBI string = "mobi" AZW string = "azw" AZW3 string = "azw3" LIT string = "lit" PRC string = "prc" FB2 string = "fb2" // DevOps/Cloud. TF string = "tf" TERRAFORM string = "terraform" ANSIBLE string = "ansible" DOCKERFILE string = "dockerfile" DOCKER string = "docker" KUBERNETES string = "k8s" BZL string = "bzl" // Script/Automation. BAKE string = "rake" FABRIC string = "fabric" FASTLANE string = "fastlane" // Scientist Data. NC string = "nc" NETCDF string = "netcdf" HDF5 string = "h5" HDF string = "hdf" FITS string = "fits" // Virtual Machine/Disk Image. IMG string = "img" VDI string = "vdi" VMDK string = "vmdk" VHD string = "vhd" VHDX string = "vhdx" // Log/temp. LOG string = "log" LOGS string = "logs" LOCKFILE string = "lockfile" PID string = "pid" DUMP string = "dump" TMP string = "tmp" TEMP string = "temp" BAK string = "bak" OLD string = "old" CACHE string = "cache" // Other. TORRENT string = "torrent" PART string = "part" DESKTOP string = "desktop" LNK string = "lnk" )
const ( MD5 string = "md5" SHA1 string = "sha1" SHA256 string = "sha256" SHA512 string = "sha512" )
Hash algorithms.
const ( MimePlain = "text/plain" MimePowerPoint = "application/vnd.ms-powerpoint" MimeGzip = "application/gzip" MimePython = "text/x-python" MimeJSON = "application/json" MimeX509Cert = "application/x-x509-ca-cert" MimeOctetStream = "application/octet-stream" )
const Unknown = "Unknown"
Variables ¶
var ( // ErrFileNotFound is returned when a file does not exist. ErrFileNotFound = errors.New("file not found") // ErrDirNotFound is returned when a directory does not exist. ErrDirNotFound = errors.New("directory not found") // ErrFileIsDir is returned when a file path points to a directory. ErrFileIsDir = errors.New("path is a directory") // ErrDirIsFile is returned when a directory path points to a file. ErrDirIsFile = errors.New("path is a file") // ErrFileAlreadyExist is returned when a file already exist. ErrFileAlreadyExist = errors.New("file already exist") // ErrEmptySource is returned when no source files are provided. ErrEmptySource = errors.New("no source files provided") // ErrPermissionDenied is returned when file access is denied. ErrPermissionDenied = errors.New("permission denied") // ErrPathIsTainted is returned when a path is tainted. ErrPathIsTainted = errors.New("filepath is tainted") )
var ( // FilterDirByName returns a filter that matches directories by exact name. FilterDirByName = func(name string) FilterDir { return func(f *DirInfo) bool { return name == f.Name } } // FilterDirByRegEx returns a filter that matches directories by regex pattern. FilterDirByRegEx = func(regex regexp.Regexp) FilterDir { return func(f *DirInfo) bool { return regex.MatchString(f.Name) } } // FilterDirBySizeGreater returns a filter that matches directories larger than the given size. FilterDirBySizeGreater = func(size int64) FilterDir { return func(f *DirInfo) bool { return f.Size > size } } // FilterDirBySizeLower returns a filter that matches directories smaller than the given size. FilterDirBySizeLower = func(size int64) FilterDir { return func(f *DirInfo) bool { return f.Size < size } } // FilterDirByNbFilesGreater returns a filter that matches directories with more files than the given count. FilterDirByNbFilesGreater = func(nb int64) FilterDir { return func(f *DirInfo) bool { return f.Nbfiles > nb } } // FilterDirByNbFilesLower returns a filter that matches directories with fewer files than the given count. FilterDirByNbFilesLower = func(nb int64) FilterDir { return func(f *DirInfo) bool { return f.Nbfiles < nb } } // FilterDirByNbFilesEqual returns a filter that matches directories with exactly the given number of files. FilterDirByNbFilesEqual = func(nb int64) FilterDir { return func(f *DirInfo) bool { return f.Nbfiles == nb } } // FilterFileByName returns a filter that matches files by exact name. FilterFileByName = func(name string) FilterFile { return func(f *FileInfo) bool { return name == f.Name } } // FilterFileByRegEx returns a filter that matches files by regex pattern. FilterFileByRegEx = func(regex regexp.Regexp) FilterFile { return func(f *FileInfo) bool { return regex.MatchString(f.Name) } } // FilterFileByExt returns a filter that matches files by extension. FilterFileByExt = func(ext string) FilterFile { return func(f *FileInfo) bool { return strings.ToLower(ext) == f.GetExt() } } // FilterFileByCategory returns a filter that matches files by category. FilterFileByCategory = func(category string) FilterFile { return func(f *FileInfo) bool { ext := f.GetExt() if cat := GetFileDescCat(ext); cat != Unknown { return strings.EqualFold(cat, category) } return false } } // FilterFileByMimeType returns a filter that matches files by MIME type. FilterFileByMimeType = func(mimeType string) FilterFile { return func(f *FileInfo) bool { ext := f.GetExt() return GetMimeType(ext) == mimeType } } // FilterFileBySizeGreater returns a filter that matches files larger than the given size. FilterFileBySizeGreater = func(size int64) FilterFile { return func(f *FileInfo) bool { return f.Size > size } } // FilterFileBySizeLower returns a filter that matches files smaller than the given size. FilterFileBySizeLower = func(size int64) FilterFile { return func(f *FileInfo) bool { return f.Size < size } } // FilterFileByCreatedAfter returns a filter that matches files created after the given time. FilterFileByCreatedAfter = func(datetime time.Time) FilterFile { return func(f *FileInfo) bool { return f.Created.UnixNano() > datetime.UnixNano() } } // FilterFileByCreatedBefore returns a filter that matches files created before the given time. FilterFileByCreatedBefore = func(datetime time.Time) FilterFile { return func(f *FileInfo) bool { return f.Created.UnixNano() < datetime.UnixNano() } } // FilterFileByUpdatedAfter returns a filter that matches files updated after the given time. FilterFileByUpdatedAfter = func(datetime time.Time) FilterFile { return func(f *FileInfo) bool { return f.Updated.UnixNano() > datetime.UnixNano() } } // FilterFileByUpdatedBefore returns a filter that matches files updated before the given time. FilterFileByUpdatedBefore = func(datetime time.Time) FilterFile { return func(f *FileInfo) bool { return f.Updated.UnixNano() < datetime.UnixNano() } } )
Functions ¶
func ConcatDir ¶
func ConcatDir(src, dst string, filter FilterFile, perm os.FileMode) error
ConcatDir concatenates all files matching the given filter in a source directory.
func ConcatFiles ¶
ConcatFiles concatenates all given files into one.
func CopyDir ¶
CopyDir copies the entire source directory and sub-directories to a destination directory.
func FileHash ¶
FileHash calculates the hash of a file using the specified algorithm (md5, sha1, sha256, sha512).
func FormatSize ¶
FormatSize formats a byte count into a human-readable string (e.g., "1.5 MB").
func GetAllExtensions ¶
func GetAllExtensions() []string
func GetFileDescCat ¶
GetFileDescCat returns the category for a given extension.
func GetFileDescName ¶
GetFileDescName returns the human-readable name for a given extension.
func GetMimeType ¶
GetMimeType returns the MIME type for a given extension.
func IsFileBinary ¶
IsFileBinary returns whether a file with the given extension is binary.
func IsFileCompressed ¶
IsFileCompressed returns whether a file with the given extension is typically compressed.
func IsFileExecutable ¶
IsFileExecutable returns whether a file with the given extension is executable.
func MoveDir ¶ added in v0.2.5
MoveDir moves a directory and all its contents to a destination directory.
Types ¶
type DirInfo ¶
DirInfo represents information about a directory.
func ListDirs ¶ added in v0.2.2
ListDirs lists all directories recursively within the given directory. It returns a slice of DirInfo for each directory found. If a filter is provided, only directories matching the filter are returned.
func (*DirInfo) FormatSize ¶
FormatSize returns a human-readable string representation of the directory size.
type DirStats ¶
type DirStats struct {
TotalFiles int64
TotalDirs int64
TotalSize int64
OldestFile time.Time
NewestFile time.Time
AverageSize int64
}
DirStats represents statistics about a directory.
func GetDirStats ¶
GetDirStats calculates statistics for a directory (total files, size, oldest/newest file).
func (*DirStats) FormatSize ¶
FormatSize returns a human-readable string representation of the total size.
type FileDesc ¶
type FileDesc struct {
Name string
Category string
MimeType string
IsBinary bool
IsCompressed bool
IsExecutable bool
}
FileDesc describes a file type with its properties.
func GetFileDesc ¶
GetFileDesc returns the file description for a given extension.
type FileInfo ¶
type FileInfo struct {
Path string
Name string
Ext string
Size int64
Created time.Time
Updated time.Time
}
FileInfo represents information about a file.
func ListFiles ¶
func ListFiles(directory string, filter FilterFile) ([]*FileInfo, error)
ListFiles lists all files within the given directory. It returns a slice of FileInfo for each file found. If a filter is provided, only files matching the filter are returned.
func WalkFiles ¶
func WalkFiles(directory string, filter FilterFile) ([]*FileInfo, error)
WalkFiles recursively walks through a directory and lists all files. It returns a slice of FileInfo for each file found. If a filter is provided, only files matching the filter are returned.
func (*FileInfo) FormatSize ¶
FormatSize returns a human-readable string representation of the file size.
type FilterFile ¶
FilterFile is a function type for filtering files.