fileutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanInvalidChars

func CleanInvalidChars(fileName string) string

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

func Cp(src, dst string) error

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

func GetAbsolutePath(path string) (string, error)

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

func GetBaseName(filePath string) string

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

func GetExtension(filePath string) string

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

func IsDir(path string) bool

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

func IsEmpty(path string) (bool, error)

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

func IsFile(path string) bool

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

func IsFileNameValid(fileName string) bool

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

func Mkdir(path string) error

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

func Mv(src, dst string) error

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

func Rm

func Rm(path string) error

Rm removes a file or directory. If it's a directory, it removes all contents recursively.

Parameters: - path: the path of the file or directory to remove

Returns: - error: if an error occurs

func Touch

func Touch(path string) error

Touch creates an empty file if it doesn't exist or updates the modified time if it does.

Parameters: - path: the path of the file to touch

Returns: - error: if an error occurs

Types

This section is empty.

Jump to

Keyboard shortcuts

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