dirSize

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirectoryInfo

type DirectoryInfo struct {
	DirCount  int64
	FileCount int64
	TotalSize int64
}

func GetDirInfo

func GetDirInfo(fSys fs.FS) (dirInfo DirectoryInfo, errs []error)

GetDirInfo Traverse each root of the file tree in parallel returning the total file count and total size of all the files.

Example
tmpDir, err := os.MkdirTemp("", "example_test")
check(err)
tmpDir2, err := os.MkdirTemp(tmpDir, "example_test2")
check(err)

test123, err := os.CreateTemp(tmpDir, "test_123")
check(err)
testABC, err := os.CreateTemp(tmpDir2, "test_abc")
check(err)
defer func() {
	_ = test123.Close()
	_ = testABC.Close()
}()

dirInfo, _ := dirSize.GetDirInfo(os.DirFS("."))

fmt.Printf("%d files  size: %1.f\n", dirInfo.FileCount, float64(dirInfo.TotalSize))
Output:

2 files  size: 0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL