filepath

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectFiles

func CollectFiles(dir string, excludeList []string) (fileList []string, err error)

CollectFiles 取得資料夾下各個檔案的路徑位置

Example

蒐集指定資料夾內的所有檔案, 本範例的排除項目為{sub和sub2資料夾內所有的md}

package main

import (
	"fmt"
	"github.com/CarsonSlovoka/go-pkg/v2/path/filepath"
)

func main() {
	fileList, err := filepath.CollectFiles("./testdata", []string{`testdata\\sub\\.*\.md`, `testdata\\sub2\\.*\.md`})
	if err != nil {
		panic(err)
	}
	fmt.Println(len(fileList))

	fileList, err = filepath.CollectFiles("./testdata", nil)
	if err != nil {
		panic(err)
	}
	fmt.Println(len(fileList))

}
Output:

5
9

func CollectFilesFromFS

func CollectFilesFromFS(fs embed.FS, dirPaths, excludeExtName []string, isRecursive bool) (filepathList []string, err error)

CollectFilesFromFS 蒐集FS中所指定的資料夾路徑底下內各個檔案路徑位置

Example

蒐集embed中特定資料夾路徑其包含的所有檔案路徑

package main

import (
	"embed"
	"fmt"
	"github.com/CarsonSlovoka/go-pkg/v2/path/filepath"
)

//go:embed testdata/*
var testFS embed.FS

func main() {
	fileList, err := filepath.CollectFilesFromFS(testFS, []string{"testdata"}, []string{".md"}, true)
	if err != nil {
		panic(err)
	}
	fmt.Println(len(fileList))

	fileList, err = filepath.CollectFilesFromFS(testFS, []string{"testdata"}, []string{".md"}, false)
	if err != nil {
		panic(err)
	}
	fmt.Println(len(fileList))

	fileList, _ = filepath.CollectFilesFromFS(testFS, []string{"testdata/sub"}, nil, true)
	fmt.Println(len(fileList))

	fileList, _ = filepath.CollectFilesFromFS(testFS, []string{"testdata/sub", "testdata/sub2"}, nil, false)
	fmt.Println(len(fileList))
}
Output:

4
2
4
6

Types

This section is empty.

Jump to

Keyboard shortcuts

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