fsutils

package
v0.0.0-...-c778a73 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 9 Imported by: 0

README

File System Utilities

  • FormatFileSize: Formats a file size given in bytes into a human-readable string with appropriate units (B, KB, MB, GB, TB).

  • FindFiles: Searches for files with the specified extension in the given root directory and returns a slice of matching file paths.

  • GetDirectorySize: Calculates the total size (in bytes) of all files within the specified directory.

  • FilesIdentical: Compares two files byte by byte to determine if they are identical.

  • DirsIdentical: Compares two directories to determine if they are identical.

  • GetFileMetadata: Retrieves metadata for a specified file path. Returns a FileMetadata struct that can be marshaled to JSON.

Examples:

For examples of each function, please checkout EXAMPLES.md


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirsIdentical

func DirsIdentical(dir1, dir2 string) (bool, error)

DirsIdentical compares two directories to determine if they are identical It returns true if both directories contain the same files with identical content, and false otherwise

func FilesIdentical

func FilesIdentical(file1, file2 string) (bool, error)

FilesIdentical compares two files byte by byte to determine if they are identical

func FindFiles

func FindFiles(root string, extension string) ([]string, error)

FindFiles searches for files with the specified extension in the given root directory and returns a slice of matching file paths.

func FormatFileSize

func FormatFileSize(size int64) string

FormatFileSize formats a file size given in bytes into a human-readable string with appropriate units (B, KB, MB, GB, TB).

func GetDirectorySize

func GetDirectorySize(path string) (int64, error)

GetDirectorySize calculates the total size (in bytes) of all files within the specified directory

Types

type ByteSize

type ByteSize int64
const (
	KB ByteSize = 1024
	MB ByteSize = KB * 1024
	GB ByteSize = MB * 1024
	TB ByteSize = GB * 1024
)

type FileMetadata

type FileMetadata struct {
	Name    string      `json:"name"`
	Size    int64       `json:"size"`
	IsDir   bool        `json:"is_dir"`
	ModTime time.Time   `json:"mod_time"`
	Mode    os.FileMode `json:"mode"`
	Path    string      `json:"path"`
	Ext     string      `json:"ext"`
	Owner   string      `json:"owner"`
}

func GetFileMetadata

func GetFileMetadata(filePath string) (FileMetadata, error)

GetFileMetadata retrieves metadata for the specified file path. It returns a FileMetadata struct containing details about the file.

Jump to

Keyboard shortcuts

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