files

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists added in v1.1.1

func FileExists(path string) bool

func FindFiles

func FindFiles(dirPath string, ext string) ([]string, error)

FindFiles searches for files with a specific extension in the given root directory and its subdirectories.

Parameters:

  • root: The root directory to start the search from.
  • ext: The file extension to search for, or ".*" to match all files. examples: ".md", ".html", ".txt", ".*"

Returns: - []string: A slice of file paths that match the given extension. - error: An error if the search encounters any issues.

func ForEachFile

func ForEachFile(dirPath string, ext string, callback func(string) error) ([]string, error)

ForEachFile iterates over all files with a specific extension in a directory and its subdirectories.

Parameters: - dirPath: The root directory to start the search from. - ext: The file extension to search for, or ".*" to match all files. - callback: A function to be called for each file found.

Returns: - []string: A slice of file paths that match the given extension. - error: An error if the search encounters any issues.

func GetAllFilesInDirectory

func GetAllFilesInDirectory(dirPath string) ([]string, error)

GetAllFilesInDirectory returns all file paths in the given directory (non-recursive).

Parameters: - dirPath: The directory path to read.

Returns: - []string: A slice of full file paths in the directory. - error: An error if the directory cannot be read.

func GetContentFiles

func GetContentFiles(dirPath string, ext string) ([]string, error)

GetContentFiles searches for files with a specific extension in the given directory and its subdirectories.

Parameters: - dirPath: The directory path to start the search from. - ext: The file extension to search for.

Returns: - []string: A slice of file paths that match the given extension. - error: An error if the search encounters any issues.

func GetContentFilesAsMap added in v1.0.3

func GetContentFilesAsMap(dirPath string, ext string) (map[string]string, error)

GetContentFilesAsMap searches for files with a specific extension in the given directory and its subdirectories.

Parameters: - dirPath: The directory path to start the search from. - ext: The file extension to search for.

Returns: - map[string]string: A map where keys are file paths and values are file contents. - error: An error if the search encounters any issues.

func LoadFromJsonFile added in v1.1.1

func LoadFromJsonFile[T any](path string) (T, error)

func ReadTextFile

func ReadTextFile(path string) (string, error)

ReadTextFile reads the contents of a text file at the given path and returns the contents as a string.

Parameters: - path: the path to the text file.

Returns: - string: the contents of the text file as a string. - error: an error if the file cannot be read.

func SaveToJsonFile added in v1.1.1

func SaveToJsonFile[T any](path string, data T) error

func WriteTextFile

func WriteTextFile(path, content string) error

Types

type FileContent added in v1.0.3

type FileContent struct {
	FileName string
	Content  string
}

FileContent represents a file with its name and content.

func GetContentFilesWithNames added in v1.0.3

func GetContentFilesWithNames(dirPath string, ext string) ([]FileContent, error)

GetContentFilesWithNames searches for files with a specific extension in the given directory and its subdirectories.

Parameters: - dirPath: The directory path to start the search from. - ext: The file extension to search for.

Returns: - []FileContent: A slice of FileContent structs containing file names and their contents. - error: An error if the search encounters any issues.

Jump to

Keyboard shortcuts

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