{"id":19509569,"url":"https://github.com/raspi/dirscanner","last_synced_at":"2025-04-26T03:31:57.420Z","repository":{"id":57549829,"uuid":"141750905","full_name":"raspi/dirscanner","owner":"raspi","description":"dirscanner is a recursive file lister which uses channels for go.","archived":false,"fork":false,"pushed_at":"2019-04-06T19:42:14.000Z","size":28,"stargazers_count":25,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T07:35:14.047Z","etag":null,"topics":["directory","files","go","golang","recursive"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raspi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-20T19:37:04.000Z","updated_at":"2023-11-29T11:38:58.000Z","dependencies_parsed_at":"2022-09-10T06:12:40.475Z","dependency_job_id":null,"html_url":"https://github.com/raspi/dirscanner","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/raspi%2Fdirscanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspi%2Fdirscanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspi%2Fdirscanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspi%2Fdirscanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raspi","download_url":"https://codeload.github.com/raspi/dirscanner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250926824,"owners_count":21509044,"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":["directory","files","go","golang","recursive"],"created_at":"2024-11-10T23:12:29.451Z","updated_at":"2025-04-26T03:31:56.828Z","avatar_url":"https://github.com/raspi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dirscanner\n`dirscanner` is a recursive file lister which uses channels for go.\n\n## Why?\nWhen there's 1000000+ files in multiple directories crawling can take minutes. With a `dirscanner` channel you can start parsing files more quickly.\n\n## Features\n\n* You can provide a filter function to the scanner which validates what files will be sent for processing. For example: get only files that are between 1-10 MiB.\n\n## Example usage:\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"time\"\n\t\"github.com/raspi/dirscanner\"\n\t\"runtime\"\n\t\"os\"\n\t\"sort\"\n)\n\n// Example custom file validator\nfunc validateFile(info os.FileInfo) bool {\n\treturn info.Mode().IsRegular()\n}\n\nfunc main() {\n\tvar err error\n\n\tworkerCount := runtime.NumCPU()\n\t//workerCount := 1\n\n\ts := dirscanner.New()\n\n\terr = s.Init(workerCount, validateFile)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer s.Close()\n\n\terr = s.ScanDirectory(`/home/raspi`)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tlastDir := ``\n\tlastFile := ``\n\tfileCount := uint64(0)\n\n\t// Ticker for stats\n\tticker := time.NewTicker(time.Second * 1)\n\tdefer ticker.Stop()\n\tnow := time.Now()\n\n\tsortedBySize := map[uint64][]string{}\n\nscanloop:\n\tfor {\n\t\tselect {\n\n\t\tcase \u003c-s.Finished: // Finished getting file list\n\t\t\tlog.Printf(`got all files`)\n\t\t\tbreak scanloop\n\n\t\tcase e, ok := \u003c-s.Errors: // Error happened, handle, discard or abort\n\t\t\tif ok {\n\t\t\t\tlog.Printf(`got error: %v`, e)\n\t\t\t\t//s.Aborted \u003c- true // Abort\n\t\t\t}\n\n\n\t\tcase info, ok := \u003c-s.Information: // Got information where worker is currently\n\t\t\tif ok {\n\t\t\t\tlastDir = info.Directory\n\t\t\t}\n\n\n\t\tcase \u003c-ticker.C: // Display some progress stats\n\t\t\tlog.Printf(`%v Files scanned: %v Last file: %#v Dir: %#v`, time.Since(now).Truncate(time.Second), fileCount, lastFile, lastDir)\n\n\t\tcase res, ok := \u003c-s.Results:\n\t\t\tif ok {\n\t\t\t\t// Process file:\n\t\t\t\tlastFile = res.Path\n\t\t\t\tfileCount++\n\t\t\t\tsortedBySize[res.Size] = append(sortedBySize[res.Size], res.Path)\n\t\t\t\t//time.Sleep(time.Millisecond * 100)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Sort\n\tvar keys []uint64\n\n\tfor k, _ := range sortedBySize {\n\t\tkeys = append(keys, k)\n\t}\n\n\tsort.Slice(keys, func(i, j int) bool { return keys[i] \u003c keys[j] })\n\n\t// Print in size order\n\tfor _, k := range keys {\n\t\tlog.Printf(`S:%v C:%v %v`, k, len(sortedBySize[k]), sortedBySize[k])\n\t}\n\n\tlog.Printf(`last: %v`, lastFile)\n\tlog.Printf(`count: %v`, fileCount)\n\n}\n```\n## Installation\nTo install this package, simply go get it:\n\n    go get -u github.com/raspi/dirscanner\n\n## Dependencies\nThere are no 3rd party package dependencies.\n\n## Projects using this library\n* https://github.com/raspi/duplikaatti\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraspi%2Fdirscanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraspi%2Fdirscanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraspi%2Fdirscanner/lists"}