Documentation
¶
Overview ¶
Package fileutil provides utility functions for handling file names and paths across different operating systems. This package ensures that file names are valid and cleans invalid characters based on the operating system's rules.
Package fileutil provides utility functions for handling file names and paths across different operating systems. This package ensures that file names are valid and cleans invalid characters based on the operating system's rules.
Index ¶
- func CleanInvalidChars(fileName string) string
- func Cp(src, dst string) error
- func GetAbsolutePath(path string) (string, error)
- func GetBaseName(filePath string) string
- func GetExtension(filePath string) string
- func IsDir(path string) bool
- func IsEmpty(path string) (bool, error)
- func IsFile(path string) bool
- func IsFileNameValid(fileName string) bool
- func Mkdir(path string) error
- func Mv(src, dst string) error
- func Rm(path string) error
- func Touch(path string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanInvalidChars ¶
CleanInvalidChars cleans invalid characters from the file name based on the current operating system. For Windows, it replaces \ / : * ? " < > | with _. For Linux and macOS, it replaces / with _. For unknown systems, it defaults to Linux-like behavior.
Parameters: - fileName: the name of the file to be cleaned
Returns: - string: the cleaned file name
func Cp ¶
Cp copies a file or directory. If the source is a directory, it copies recursively.
Parameters: - src: the source file or directory - dst: the destination file or directory
Returns: - error: if an error occurs
func GetAbsolutePath ¶
GetAbsolutePath returns the absolute path for a given relative or classpath file. It resolves the absolute path based on the current working directory. If the operation fails, it returns an error.
Parameters: - path: the relative or classpath file
Returns: - string: the absolute path - error: if an error occurs
func GetBaseName ¶
GetBaseName returns the base name of the file without the extension. For example, given the file path "example/test/file.txt", it will return "file".
Parameters: - filePath: the path of the file
Returns: - string: the base name of the file
func GetExtension ¶
GetExtension returns the file extension. For example, given the file path "example/test/file.txt", it will return ".txt".
Parameters: - filePath: the path of the file
Returns: - string: the file extension
func IsDir ¶
IsDir checks if the given path is a directory.
Parameters: - path: the path to check
Returns: - bool: true if the path is a directory, false otherwise
func IsEmpty ¶
IsEmpty checks if a file or directory is empty.
Parameters: - path: the path of the file or directory
Returns: - bool: true if the file or directory is empty, false otherwise - error: if an error occurs
func IsFile ¶
IsFile checks if the given path is a file.
Parameters: - path: the path to check
Returns: - bool: true if the path is a file, false otherwise
func IsFileNameValid ¶
IsFileNameValid checks if the file name is valid based on the current operating system. For Windows, it checks for the presence of \ / : * ? " < > |. For Linux and macOS, it checks for the presence of /. For unknown systems, it defaults to Linux-like behavior.
Parameters: - fileName: the name of the file to be checked
Returns: - bool: true if the file name is valid, false otherwise
func Mkdir ¶
Mkdir creates a directory and all necessary parent directories.
Parameters: - path: the path of the directory to create
Returns: - error: if an error occurs
func Mv ¶
Mv renames or moves a file/directory from src to dst.
Parameters: - src: the source file or directory - dst: the destination file or directory
Returns: - error: if an error occurs
Types ¶
This section is empty.