Documentation ¶
Index ¶
- func AppendToFile(filePath string, contents ...string)
- func FileExists(filePath string) (bool, error)
- func GetAllFileNamesInDirectory(directoryPath string) (map[string]string, error)
- func GetFilesEndingIn(directoryPath string, extensions ...string) ([]string, error)
- func MediaDownloader(dest, url string) (filePath string, err error)
- func ReadWholeFileLineByLine(path string) ([]string, error)
- func SplitPath(filePath string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendToFile ¶
AppendToFile is a function that appends content to a file, each content on a new line.
Panics if it fails to open the file or write to it.
Parameters:
- filePath: A string representing the path to the file.
- contents: A variadic parameter of strings representing the content to be appended.
func FileExists ¶ added in v0.2.9
FileExists checks if a file exists at the given path.
Parameters:
- filePath: A string representing the path to the file.
Returns:
- A boolean indicating whether the file exists.
func GetAllFileNamesInDirectory ¶
GetAllFileNamesInDirectory is a function that retrieves all file names in a given directory and their extensions.
Parameters:
- directoryPath: A string representing the path to the directory.
Returns:
- map[string]string: A map where the keys are the file paths and the values are the file extensions.
- error: An error if it fails to read the directory or any of its files.
func GetFilesEndingIn ¶
GetFilesEndingIn is a function that retrieves all files in a given directory that have a specified extension. This function does not search subdirectories.
Parameters:
- directoryPath: A string representing the path to the directory.
- extensions: A variadic parameter of strings representing the file extensions to match.
Returns:
- []string: A slice of strings representing the paths to the matching files.
- error: An error if it fails to read the directory.
func MediaDownloader ¶
MediaDownloader downloads a file from the given URL and saves it to the specified destination.
The name of the file is derived from the URL and it does not download the file if the name already exists in the destination.
Parameters:
- dest: A string representing the path to the directory where the file will be saved.
- url: A string representing the URL of the file to download.
Returns:
- string: The path to the downloaded file.
- error: An error if the download fails.
Example:
file_path, err := MediaDownloader("/path/to/destination", "http://example.com/file.mp3") if err != nil { log.Fatal(err) } fmt.Println(file_path) // Output: /path/to/destination/file.mp3
func ReadWholeFileLineByLine ¶
ReadWholeFileLineByLine reads a file from the provided path line by line and returns a slice of strings, where each string represents a line from the file. If an error occurs while opening the file, the function returns the error and a nil slice.
Parameters:
- path: The path to the file to be read.
Returns:
- []string: A slice of strings where each string is a line from the file.
- error: An error if one occurred while opening or scanning the file.
Types ¶
This section is empty.