Skip to content

Commit 832e408

Browse files
committed
Filesystem Functions #3
Fixes #9
1 parent 666076d commit 832e408

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

directory_filesystem.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ func FileType(fs string) (string, error) {
183183
return contentType, nil
184184
}
185185

186+
// Glob - Find pathnames matching a pattern.
187+
// Original : https://www.php.net/manual/en/function.glob.php
188+
// The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells.
189+
func Glob(path string) (matches []string, err error) {
190+
return filepath.Glob(path)
191+
}
186192

187193
// IsDir - Tells whether the filename is a directory.
188194
// Original : https://www.php.net/manual/en/function.is-dir.php
@@ -240,7 +246,54 @@ func MkDir(path string, mode os.FileMode) error {
240246
return os.Mkdir(path, mode)
241247
}
242248

249+
// ReadLink - Returns the target of a symbolic link.
250+
// Original : https://www.php.net/manual/en/function.readlink.php
251+
// readlink() does the same as the readlink C function.
252+
func ReadLink(path string) (string, error){
253+
li, err := os.Readlink(path)
254+
if err != nil {
255+
return "", err
256+
}
257+
return li, err
258+
}
259+
260+
// RealPath - Returns canonicalized absolute pathname.
261+
// Original : https://www.php.net/manual/en/function.realpath.php
262+
// realpath() expands all symbolic links and resolves references to /./, /../ and extra / characters in the input path and returns the canonicalized absolute pathname.
263+
func RealPath(path string) (string, error) {
264+
return filepath.Abs(path)
265+
}
266+
267+
// Rename - Renames a file or directory.
268+
// Original : https://www.php.net/manual/en/function.rename.php
269+
// Attempts to rename oldname to newname, moving it between directories if necessary. If renaming a file and newname exists, it will be overwritten. If renaming a directory and newname exists, this function will emit a warning.
270+
func Rename(oldpath, newpath string) error {
271+
return os.Rename(oldpath, newpath)
272+
}
273+
274+
// RmDir — Removes directory.
275+
// Original : https://www.php.net/manual/en/function.rmdir.php
276+
// Attempts to remove the directory named by dirname. The directory must be empty, and the relevant permissions must permit this. A E_WARNING level error will be generated on failure.
277+
func RmDir(path string) error {
278+
return os.RemoveAll(path)
279+
}
280+
281+
// Stat - Gives information about a file.
282+
// Original : https://www.php.net/manual/en/function.stat.php
283+
// Gathers the statistics of the file named by filename. If filename is a symbolic link, statistics are from the file itself, not the symlink. Prior to PHP 7.4.0, on Windows NTS builds the size, atime, mtime and ctime statistics have been from the symlink, in this case.
284+
func Stat(name string) (os.FileInfo, error) {
285+
return os.Stat(name)
286+
}
287+
288+
// Unlink - Deletes a file.
289+
// Original : https://www.php.net/manual/en/function.unlink.php
290+
// Deletes filename. Similar to the Unix C unlink() function. An E_WARNING level error will be generated on failure.
291+
func Unlink(name string) error {
292+
return Delete(name)
293+
}
294+
243295
// ByteCountIEC - Bytecount & Humanize Bytes
296+
// Complete calculator for DiskFreeSize
244297
func ByteCountIEC(b uint64) string {
245298
const unit = 1024
246299
if b < unit {

0 commit comments

Comments
 (0)