FileManager

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToFile

func AppendToFile(filePath string, contents ...string)

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

func FileExists(filePath string) (bool, error)

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

func GetAllFileNamesInDirectory(directoryPath string) (map[string]string, error)

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

func GetFilesEndingIn(directoryPath string, extensions ...string) ([]string, error)

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

func MediaDownloader(dest, url string) (filePath string, err error)

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

func ReadWholeFileLineByLine(path string) ([]string, error)

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.

func SplitPath added in v0.2.3

func SplitPath(filePath string) []string

SplitPath splits a file path into its components, where each component is a part of the file path.

Parameters:

  • filePath: A string representing the path to the file.

Returns:

  • []string: A slice of strings representing the parts of the file path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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