1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-26 23:10:42 +02:00

сделал FindFoldersTree(dir string, NeedFolders, NeedFiles, NeedDot bool, MassExclude []string)

This commit is contained in:
Nikitin Aleksandr
2024-03-14 11:35:25 +03:00
parent e0bd78ef61
commit 2f16f68c7a
2 changed files with 20 additions and 6 deletions

View File

@@ -25,7 +25,7 @@ func (f *Folder) String() string {
}
// FindFoldersTree - возвращает дерево каталогов и файлов, начиная с директории dir
func FindFoldersTree(dir string, NeedFolders, NeedFiles, NeedDot bool, exclude string) *Folder {
func FindFoldersTree(dir string, NeedFolders, NeedFiles, NeedDot bool, MassExclude []string) *Folder {
dir = path.Clean(dir)
var tree *Folder
var nodes = map[string]interface{}{}
@@ -57,11 +57,15 @@ func FindFoldersTree(dir string, NeedFolders, NeedFiles, NeedDot bool, exclude s
// найдём название Папки/Файла
var Name string
var FolderName string
switch value.(type) {
case *File:
Name = value.(*File).Name
case *Folder:
Name = value.(*Folder).Name
{
Name = value.(*Folder).Name
FolderName = value.(*Folder).FileName
}
}
// проверка скрытые файлы с точкой
@@ -69,10 +73,20 @@ func FindFoldersTree(dir string, NeedFolders, NeedFiles, NeedDot bool, exclude s
continue
}
// проверка кроме exclude
if exclude != "" && len(Name) >= len(exclude) && Name[0:len(exclude)] == exclude {
continue
// проверка кроме MassExclude
if len(MassExclude) > 0 {
for _, v := range MassExclude {
if Name == v {
continue
}
if FolderName == v {
continue
}
}
}
//if MassExclude != "" && len(Name) >= len(MassExclude) && Name[0:len(MassExclude)] == MassExclude {
// continue
//}
//
switch v := value.(type) {

View File

@@ -8,7 +8,7 @@ import (
func TestFindFolders(t *testing.T) {
//dir := `/home/user/GolandProjects/!sanek/image_packages/`
dir := micro.ProgramDir()
Otvet := FindFoldersTree(dir, true, false, false, "vendor")
Otvet := FindFoldersTree(dir, true, false, false, []string{"vendor"})
if Otvet == nil {
t.Log("TestFindFolders() error: Otvet = nil")
}