Add FileWorkspaceInfo

This commit is contained in:
George Suntres
2026-04-01 20:40:25 -04:00
parent 21fb60b7a9
commit e732870865
5 changed files with 77 additions and 5 deletions

30
file.go
View File

@@ -2,8 +2,9 @@ package commons
import (
"log"
"os"
"path/filepath"
"os"
"strings"
"path/filepath"
)
// FileDeepScan will scan dir recursively and append any files found to files.
@@ -22,4 +23,27 @@ func FileDeepScan(dir string, files *[]string) {
*files = append(*files, filepath.Join(dir, entry.Name()))
}
}
}
}
type WorkspaceInfo struct {
ParentDir string
}
// FileWorkspaceInfo given a file will return relevant information about
// its location, such as its parent directory.
func FileWorkspaceInfo(file string) *WorkspaceInfo {
// 1. break down file
clean := filepath.Clean(file)
parts := strings.Split(clean, string(filepath.Separator))
l := len(parts)
if l > 3 {
parentDir := parts[l - 2]
return &WorkspaceInfo {
ParentDir: parentDir,
}
}
return nil
}