{"id":18410265,"url":"https://github.com/racklin/go-fileutil","last_synced_at":"2025-04-12T21:59:11.105Z","repository":{"id":19369450,"uuid":"22609661","full_name":"racklin/go-fileutil","owner":"racklin","description":"Package fileutil implements some File utility functions","archived":false,"fork":false,"pushed_at":"2014-12-17T09:36:33.000Z","size":172,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T21:59:08.350Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/racklin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-04T15:37:01.000Z","updated_at":"2020-11-03T12:58:02.000Z","dependencies_parsed_at":"2022-09-13T14:51:19.946Z","dependency_job_id":null,"html_url":"https://github.com/racklin/go-fileutil","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/racklin%2Fgo-fileutil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/racklin%2Fgo-fileutil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/racklin%2Fgo-fileutil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/racklin%2Fgo-fileutil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/racklin","download_url":"https://codeload.github.com/racklin/go-fileutil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248637782,"owners_count":21137538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T03:30:25.758Z","updated_at":"2025-04-12T21:59:11.075Z","avatar_url":"https://github.com/racklin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Package fileutil implements some File utility functions.\nSimple and without get into nested if statement hell.\n\n## Using\n```go\nimport fileutil \"github.com/racklin/go-fileutil\"\n```\n\n## Document\n[godoc.org](http://godoc.org/github.com/racklin/go-fileutil)\n\n## Examples\n\n### Check File Exists\n```go\nfunc Exists(filename string) (bool, error)\n```\nExample:\n```go\n    exists, err := fileutil.Exists(\"/etc/passwd\")\n```\n\n### FileInfo\n\n#### Filesize\n```go\nfunc Size(filename string) (int64, error)\n```\nExample:\n```go\n    size, err := fileutil.Size(\"/etc/passwd\")\n```\n\n#### File Modified Time\n```go\nfunc ModTime(filename string) (time.Time, error)\n```\nor\n```go\nfunc ModTimeUnix(filename string) (int64, error)\n```\nor\n```go\nfunc ModTimeUnixNano(filename string) (int64, error)\n```\nExample:\n```go\n    mtime, err := fileutil.ModTimeUnix(\"/etc/passwd\")\n```\n\n#### File Mode and Permission\n```go\nfunc Mode(filename string) (os.FileMode, error)\nfunc Perm(filename string) (os.FileMode, error)\n```\n\n### File Read And Write\n#### Bytes Operations\n```go\nfunc Read(filename string) ([]byte, error)\nfunc Write(filename string, content []byte) error\n```\n#### String Operations\n```go\nfunc ReadString(filename string) (string, error)\nfunc WriteString(filename, content string) error\nfunc AppendString(filename, content string) error\n```\nExample:\n```go\n    func Log(message string) {\n        fileutil.AppendString(\"/var/log/test.log\", message)\n    }\n```\n### Alias\nIf you are PHPer , feels like coming home (file_put_contents/file_get_contents).\n```go\nfunc Basename(filename string) string\nfunc Dirname(filename string) string\nfunc Extname(filename string) string\nfunc Unlink(path string) error\nfunc Rmdir(path string) error\nfunc GetContents(filename string) (string, error)\nfunc PutContents(filename, content string) error\nfunc AppendContents(filename, content string) error\n```\n\n### File Copy\nCopies a file from source to destination.\nIf source and destination files exist and the same, return success.\nOtherise, using hard link between the two files. If that fail, copy the file contents.\n```go\nfunc Copy(source, dest string) (err error)\n```\nExample:\n```go\nerr := fileutil.Copy(\"/etc/passwd\", \"/tmp/passwd\")\n```\n\n### File Glob and Sort\nFind returns the FilesInfo([]FileInfo) of all files matching pattern\n```go\nfunc Find(pattern string) (FilesInfo, error)\n```\nSorting FilesInfo:\n```go\nfunc (fis FilesInfo) SortByName()\nfunc (fis FilesInfo) SortBySize()\nfunc (fis FilesInfo) SortByModTime()\nfunc (fis FilesInfo) SortByNameReverse()\nfunc (fis FilesInfo) SortBySizeReverse()\nfunc (fis FilesInfo) SortByModTimeReverse()\n```\nExample1: List file of /tmp\n```go\n    files, err := fileutil.Find(\"/tmp/*\")\n```\nExample2: Find go file in /usr/local directory\n```go\n    files, err := fileutil.Find(\"/usr/local/*/go\")\n```\nExample3: Sorting result files\n```go\n    files, err := fileutil.Find(\"/tmp/*\")\n    files.SortByName()\n```\n\n### Exec\nRuns the command and returns its standard output as string.\n```go\nfunc Exec(name string, arg ...string) (string, error)\n```\n\n## License\n\nhttp://racklin.mit-license.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fracklin%2Fgo-fileutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fracklin%2Fgo-fileutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fracklin%2Fgo-fileutil/lists"}