Documentation
¶
Index ¶
- func CreateDir(path string, perm ...os.FileMode) error
- func CreateDirPath(path string, perm ...os.FileMode) error
- func CreateFile(path string, perm ...os.FileMode) (*os.File, error)
- func DeleteDir(path string, recursive bool) error
- func DeleteFile(path string) error
- func Exists(path string) bool
- func GetFileSize(path string) (int64, error)
- func GetParentPath(filePath string) string
- func GetPermission(path string) (os.FileMode, error)
- func GetUserConfigDir() (string, error)
- func GetUserDataDir(appName string) string
- func GetUserHomeDir() (string, error)
- func GetUserLogDir(appName string) string
- func HasSpaceAvailable(path string, requiredBytes uint64) (bool, error)
- func IsDir(path string) bool
- func IsEmptyDir(path string) (bool, error)
- func IsFile(path string) bool
- func IsFileDirExists(filePath string) bool
- func IsReadable(path string) bool
- func IsSameFile(pathA, pathB string) (bool, error)
- func IsWritable(path string) bool
- func OpenFileRead(path string) (*os.File, error)
- func OpenFileWrite(path string, truncate bool, perm ...os.FileMode) (*os.File, error)
- func RetrieveFullPath(path string) (string, error)
- func SetPermission(path string, perm os.FileMode) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateDir ¶
CreateDir creates a single directory at the specified path. It automatically expands the tilde prefix ("~") before creating the folder and fails if the parent directory structure does not exist. An optional os.FileMode can be passed; if omitted, it defaults to standard permissions (0755). Returns nil on success, or an error if path expansion fails or the directory cannot be created.
func CreateDirPath ¶
CreateDirPath creates a directory path along with any necessary parent directories. It automatically expands the tilde prefix ("~") before creating the folder structure. An optional os.FileMode can be passed; if omitted, it defaults to standard permissions (0755). If the target path already exists, it does nothing and returns nil.
func CreateFile ¶
CreateFile creates a new file at the specified path, truncating it if it already exists. It automatically expands the tilde prefix ("~") before executing the operation. An optional os.FileMode can be passed; if omitted, it defaults to standard system permissions (0666). Returns a pointer to the opened file object (*os.File) ready for writing, or an error if path expansion or file creation fails.
func DeleteDir ¶
DeleteDir removes a directory at the specified path, with optional recursive deletion of all its contents. It automatically expands the tilde prefix ("~") before executing any filesystem validation or removal steps. If recursive is true, it uses os.RemoveAll to forcefully delete the folder and everything inside it; otherwise, it uses os.Remove and fails if the directory is not completely empty. Returns nil on success, or an error if path expansion fails, the path is not a directory, or the system removal operation is denied.
func DeleteFile ¶
DeleteFile removes a regular file at the specified path. It automatically expands the tilde prefix ("~") before performing the check and deletion. It explicitly fails if the targeted path is a directory to prevent accidental directory structural loss. Returns nil on success, or an error if path expansion fails, the path points to a directory, or the system removal operation is denied.
func Exists ¶
Exists checks if a file or directory exists at the given path. It automatically expands the tilde prefix ("~") using the RetrieveFullPath function before executing the check. Returns true if the target path is found on the system, or false if it does not exist or if path expansion fails.
func GetFileSize ¶
GetFileSize returns the size of the file in bytes at the specified path. It automatically expands the tilde prefix ("~") before checking the path. It explicitly returns an error if the path points to a directory or if the file does not exist. Returns the file size in bytes as an int64, or an error if path expansion, system calls, or validations fail.
func GetParentPath ¶
GetParentPath extracts and returns the parent directory path from a given file path. It automatically expands the tilde prefix ("~") using the RetrieveFullPath function before isolating the layout. Returns the parent directory string, or an empty string if the input filePath is empty or if path expansion fails.
func GetPermission ¶
GetPermission retrieves the system permission bits (os.FileMode) for the specified file or directory. It automatically expands the tilde prefix ("~") using the RetrieveFullPath function before executing the check. Returns the file mode permissions, or an error if path expansion fails or if the path does not exist.
func GetUserConfigDir ¶
GetUserConfigDir retrieves the absolute filesystem path to the current user's configuration directory. It wraps Go's native standard library call to return the appropriate standard path based on the operating system guidelines. Returns the configuration directory path string, or an error if the path cannot be determined.
func GetUserDataDir ¶
GetUserDataDir determines the standard platform-specific directory for storing application data. It accepts the application name (appName) to append to the base system path. It automatically falls back to the system's temporary directory if the user's home directory cannot be resolved. Returns the fully constructed and cleaned absolute path tailored to the target operating system guidelines.
func GetUserHomeDir ¶
GetUserHomeDir retrieves the absolute filesystem path to the current user's home directory. It acts as a wrapper around Go's native standard library call, ensuring cross-platform compatibility. Returns the home directory path string, or an error if the system environment variables or user profile cannot be resolved.
func GetUserLogDir ¶
GetUserLogDir determines the standard platform-specific directory for storing application log files. It accepts the application name (appName) to append to the base system path. It automatically falls back to the system's temporary directory if the user's home directory cannot be resolved. Returns the fully constructed and cleaned absolute path tailored to the target operating system guidelines.
func HasSpaceAvailable ¶
HasSpaceAvailable checks if the storage volume containing the specified path has at least the required number of bytes free. It accepts a filesystem path (path) and the minimum required space in bytes (requiredBytes). If the target path does not exist, it traverses upward to find the closest existing parent directory to accurately target the underlying volume. Returns true if the volume has sufficient space available for the current user, or false along with an error if the path expansion, UTF-16 conversion, or Win32 GetDiskFreeSpaceEx API call fails.
func IsDir ¶
IsDir checks if the specified path exists and points to a directory. It automatically expands the tilde prefix ("~") using the RetrieveFullPath function before executing the check. Returns true if the path is a directory, or false if it does not exist, is a regular file/symlink, or if system calls fail.
func IsEmptyDir ¶
IsEmptyDir checks if the specified directory exists and contains no files or subdirectories. It automatically expands the tilde prefix ("~") before evaluating the target directory path. Returns true if the directory is completely empty, or false along with an error if the path does not exist, is not a directory, or if read permissions are denied.
func IsFile ¶
IsFile checks if the specified path exists and points to a regular file. It automatically expands the tilde prefix ("~") using the RetrieveFullPath function before executing the check. Returns true if the path is a regular file, or false if it does not exist, is a directory/symlink, or if system calls fail.
func IsFileDirExists ¶
IsFileDirExists extracts the parent directory path from a given file path and checks if it exists as a valid directory. It automatically expands the tilde prefix ("~") before isolating the parent directory layout. Returns true if the parent directory structure exists on the system, or false if the path is empty, expansion fails, or the directory does not exist.
func IsReadable ¶
IsReadable checks if the current application process has sufficient permissions to read the file or directory at the specified path. It automatically expands the tilde prefix ("~") and robustly handles both regular files and directory permission boundaries across different operating systems. Returns true if the path can be successfully read, or false if permissions are denied or if the path does not exist.
func IsSameFile ¶
IsSameFile checks if two different paths point to the exact same physical file or directory on the storage device. It automatically expands the tilde prefix ("~") on both inputs and resolves any symbolic links encountered. It relies on Go's native os.SameFile mechanism to compare low-level system identities like inodes or file IDs. Returns true if both paths target the identical filesystem resource, or false along with an error if metadata retrieval fails.
func IsWritable ¶
IsWritable checks if the current application process has sufficient permissions to modify or write to the file or directory at the specified path. It automatically expands the tilde prefix ("~") and tests directories by attempting to create a temporary file inside them, or files by opening them in write-only append mode. Returns true if the path can be written to, or false if permissions are denied, if the path does not exist, or if the test operations fail.
func OpenFileRead ¶
OpenFileRead opens an existing file exclusively in read-only mode. It automatically expands the tilde prefix ("~") using the RetrieveFullPath function before attempting to open the path. Returns a pointer to the opened file object (*os.File) ready for reading, or an error if path expansion fails or if the file does not exist.
func OpenFileWrite ¶
OpenFileWrite opens a file for writing, creating it with the specified or default permissions (0644) if it does not exist. It automatically expands the tilde prefix ("~") before opening the path. If truncate is true, the file's existing content is cleared upon opening; otherwise, new data is appended to the end. An optional os.FileMode can be passed to override the default creation permissions. Returns a pointer to the opened file object (*os.File) ready for writing, or an error if path expansion or file opening fails.
func RetrieveFullPath ¶
RetrieveFullPath replaces the tilde prefix ("~") with the user's home directory and strictly resolves the final result into a clean, absolute filesystem path. If the path is relative, it anchors it to the current working directory, removing any redundancies like "." or "..". Returns the fully resolved absolute path, or an error if system paths cannot be determined.
func SetPermission ¶
SetPermission updates the filesystem permission bits (os.FileMode) for the specified file or directory. It automatically expands the tilde prefix ("~") using the RetrieveFullPath function before applying the changes. Returns nil on success, or an error if path expansion fails, the path does not exist, or the operation is denied.
Types ¶
This section is empty.