mirror of
https://github.com/studiokaiji/nostr-webhost.git
synced 2025-12-17 23:04:23 +01:00
ファイル名を変更
This commit is contained in:
45
hostr/cmd/tools/findFilePaths.go
Normal file
45
hostr/cmd/tools/findFilePaths.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 特定のパス以下のファイルを検索し、与えられたsuffixesに該当するファイルのパスのみを返す
|
||||
func FindFilesWithBasePathBySuffixes(basePath string, suffixes []string) ([]string, error) {
|
||||
filePaths := []string{}
|
||||
|
||||
err := filepath.Walk(basePath, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ディレクトリはスキップ
|
||||
if !info.IsDir() {
|
||||
// 各サフィックスに対してマッチングを試みる
|
||||
for _, suffix := range suffixes {
|
||||
// ファイル名とサフィックスがマッチした場合
|
||||
if strings.HasSuffix(strings.ToLower(info.Name()), strings.ToLower(suffix)) {
|
||||
// フルパスからbasePathまでの相対パスを計算
|
||||
relPath, err := filepath.Rel(basePath, path)
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error calculating relative path:", err)
|
||||
continue
|
||||
}
|
||||
// マッチするファイルの相対パスをスライスに追加
|
||||
filePaths = append(filePaths, "/"+relPath)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return filePaths, nil
|
||||
}
|
||||
Reference in New Issue
Block a user