This is a creation in Article, where the information may have evolved or changed. Package Main
Import (
"FMT"
"Io/ioutil"
"OS"
// "Path/filepath"
// "Strings"
)
VAR (
files []string
)
Get all files and directories under the specified directory
Func Listdir (dirpth string) (err error) {
Fmt. Println (dirpth)
Dir, err: = Ioutil. ReadDir (dirpth)
If err! = Nil {
return err
}
PTHSEP: = string (OS. PathSeparator)
// suffix = strings. ToUpper (suffix)//ignore suffix matching case
For _, Fi: = Range dir {
If Fi. Isdir () {//Ignore directory
Files1 = Append (Files1, Dirpth+pthsep+fi. Name ())
Listdir (dirpth + pthsep + fi. Name ())
Fmt. Println (dirpth + pthsep + fi. Name ())
}else{
Fmt. Println ("s")
Files d= append (files, Dirpth+pthsep+fi. Name ())
}
}
return Nil
}
Func Main () {
_ = Listdir ("/mnt/hgfs/share/mygo/src/yeesec/alchemist")
For _, Table1: = Range Files {
Fmt. Println (table1)
}
}
Or
Package Main
Import(
"FMT"
"Io/ioutil"
"OS"
// "Path/filepath"
// "strings"
)
Get all files and directories under the specified directory
Funclistdir (dirpthstring)(Files[]string, Files1 []string,errerror){
//fmt. Println (dirpth)
dir,err: =ioutil. ReadDir (dirpth)
iferr!=nil{
returnnil,nil,err
}
pthsep: =string(OS. PathSeparator)
// suffix=strings. ToUpper (suffix)//Ignore suffix matching case
for_,fi: =rangedir{
iffi. Isdir (){// Ignore directory
files1=append(files1,dirpth+pthsep+fi. Name ())
listdir (dirpth+pthsep+fi. Name ())
}else{
//fmt. Println ("s")
files=append(Files,Dirpth+pthsep+fi. Name ())
}
}
returnfiles,files1,Nil
}
FuncMain (){
files,files1,_: =listdir ("/mnt/hgfs/share/mygo/src/yeesec/alchemist" )
for_,table: =rangefiles1{
temp,_,_:=listdir (table)
for_,temp1: =rangetemp{
files=append(Files,temp1)
}
}
for_,table1: =rangefiles{
FMT. Println (table1)
}
}