# README
path - utilities and convenience wrappers for all sorts of unix and URL path operations
The heading says it all. This package is likely a great candidate for a general refactoring into more targeted Go packages, however, it has proven quite convenient for Go-Enjin to have all these sorts of things in one place.
Installation
> go get github.com/go-corelibs/path@latest
Examples
There are too many things to demonstrate, see the godoc for the full details.
Go-CoreLibs
Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.
License
Copyright 2023 The Go-CoreLibs Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# Functions
Abs is a convenience wrapper around filepath.Abs.
BackupAndOverwrite uses BackupName (passing argv along) to derive a non-existing file name, uses CopyFile to back up the current file contents and then uses Overwrite to update the original file contents.
BackupName is a more flexible version of IncrementFileBackup, with a variable length list of values configuring the backup file naming process.
Base returns the base name of the path without any file extensions.
BasePath returns the path without any primary or secondary file extensions, tertiary and other extensions present will remain as-is
Example:
BasePath("one/file.txt.tmpl.bak") == "one/file.txt".
ChmodAll uses Walk to traverse the filesystem and change all regular file permissions to the DefaultFilePerms (0660) and all directory permissions to the DefaultPathPerms (0770).
Clean is a convenience wrapper around filepath.Clean.
CleanWithSlash trims all leading and trailing space from the `path` given, uses filepath.Clean on the trimmed results.
CleanWithSlashes is a wrapper around CleanWithSlash which ensures the `clean` path begins and ends with a slash.
CopyFile copies the regular file `src` to `dst`.
Dir is a convenience wrapper around filepath.Dir.
DirSize uses filepath.WalkDir to traverse the given directory recursively and add up the size of each file present (includes hidden and any non-directory entries).
Exists returns true if the path is present on the local filesystem (could be a directory or any type of file).
Ext returns the extension of the file (without the dot).
ExtExt returns the extension of the file (without the dot) and any secondary extension found in the path
Example:
ExtExt("page.html.tmpl") => "tmpl", "html".
FileSize returns the size of regular files.
FindFileRelativeToPath looks for the named file within the directory path given and if not found, walks up the parent directories, checking each of them and returning the first named file found (as an absolute path)
The intent is something similar to how the `git` command knows it's in a repository even though the command may be run from within a subdirectory of the repository.
FindFileRelativeToPwd is a convenience wrapper for FindFileRelativeToPath, specifying the given name and a path of ".".
HasAnyExt returns true.
HasExt returns true if either the primary or secondary file extension matches the one given.
No description provided by the author
IncrementFileBackup removes the given extension if present, uses IncrementFilePath to modify the name with the extension appended.
IncrementFileName is a wrapper around IncrementLabel, equivalent to: `IncrementLabel(name, " ", "(", ")", 1)`.
IncrementFilePath is a wrapper around IncrementLabel, equivalent to: `IncrementLabel(name, ".", "", "", 1)`.
IncrementLabel examines the given label for the specific sequence of leader, prefix, one or more digits and suffix characters.
IsBackup returns true if the path ends with a tilde.
IsDir returns true if the path is an existing directory.
IsFile returns true if the path is an existing file (could be a char device, pipe or other unix goodness, but not a directory).
IsHidden returns true if the base of the path starts with a period.
IsHiddenPath returns true if any of the path segments starts with a period and will panic if filepath.Abs fails to resolve an absolute path, which is not something that just happens randomly.
No description provided by the author
IsPlainText returns true if the path is a file and the file's mimetype is of `text/plain` type.
IsRegularFile returns true if the path is an existing regular file.
Join joins the given URL path parts and uses filepath.Clean on the results.
JoinWithSlash joins the given URL path parts and uses CleanWithSlash on the results.
JoinWithSlashes joins the given URL path parts and uses CleanWithSlashes on the results.
List returns a list of directories and files, sorted in natural order with hidden things first and directories grouped before files.
ListAllDirs is similar to ListDirs except returning all directories found recursively.
ListAllFiles is similar to ListAllDirs except returning only files.
ListDirs is similar to List except returning only directories.
ListFiles is similar to ListDirs except returning only files.
ListMatching is a general purpose filesystem listing function, used by all other List functions in this package.
MatchCut returns the suffix of path if path is prefixed with the given prefix path.
MatchExact compares cleaned versions of path and prefix.
MkdirAll is a wrapper around os.MkdirAll with DefaultPathPerms (0770).
MoveFile tries to rename `src` to `dst` and if that works, nothing else is done.
No description provided by the author
Overwrite overwrites the given file, preserving existing permissions.
OverwriteWithPerms overwrites the given file and ensures the permissions are specifically the perms given.
ParseParentPaths is expecting a directory path and returns a list that walks up the total path with each item in the list
Example:
ParseParentPaths("one/two/many") == []string{ "one", "one/two", "one/two/many", }.
Permissions is a wrapper around os.Stat, returning just the stat.Mode().Perm() value and any error from the stat call.
PruneEmptyDirs finds all directories starting at the given path, checks if.
Pwd is a wrapper around os.Getwd.
ReadDir is a convenience wrapper around os.ReadDir.
ReadFile is a convenience wrapper around os.ReadFile.
SafeConcatRelPath prunes all empty and current dir paths from the list given, using TrimSlashes, then joins all the paths together, ensuring the output is prefixed with the given root, and has no leading or trailing slash and has is filepath.Clean.
SafeConcatUrlPath wraps SafeConcatRelPath with a prefixing slash making an absolute URL path.
Stat is a convenience wrapper around github.com/djherbis/times.Stat.
TopDirectory returns the top directory in the path given or an empty string if there are no parent directories present.
TrimDotSlash trims any leading `./` from the given path.
TrimExt returns the path without the last extension, if there are any.
TrimPrefix is like strings.TrimPrefix but for URL paths so that the prefix looked for is a prefixing URL path regardless of any slashes present in the prefix or path argument values.
TrimRelativeToRoot truncates the root from path and removes any leading or trailing slashes.
TrimSlash returns the filepath cleaned and without any trailing slash.
TrimSlashes returns the filepath cleaned and without any leading or trailing slashes.
Walk is a convenience wrapper around filepath.Walk.
Which is a convenience wrapper around exec.LookPath and filepath.Abs.
# Variables
DefaultFilePerms are the default permissions used when creating new files.
DefaultPathPerms are the default permissions used when creating new directories.
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author