forked from go/golangs_learn
VIVIMAN
3 years ago
3 changed files with 65 additions and 0 deletions
@ -0,0 +1,20 @@ |
|||
package go_to_dir |
|||
|
|||
import ( |
|||
"fmt" |
|||
//"io/ioutil"
|
|||
//"log"
|
|||
"os" |
|||
"path/filepath" |
|||
) |
|||
|
|||
func main() { |
|||
pwd, _ := os.Getwd() |
|||
|
|||
//获取当前目录下的所有文件或目录信息
|
|||
filepath.Walk(pwd, func(path string, info os.FileInfo, err error) error { |
|||
fmt.Println(path) //打印path信息
|
|||
fmt.Println(info.Name()) //打印文件或目录名
|
|||
return nil |
|||
}) |
|||
} |
@ -0,0 +1,21 @@ |
|||
package go_to_dir |
|||
|
|||
|
|||
import ( |
|||
"fmt" |
|||
"io/ioutil" |
|||
"log" |
|||
"os" |
|||
) |
|||
func main() { |
|||
pwd, _ := os.Getwd() |
|||
//获取文件或目录相关信息
|
|||
fileInfoList, err := ioutil.ReadDir(pwd) |
|||
if err != nil { |
|||
log.Fatal(err) |
|||
} |
|||
fmt.Println(len(fileInfoList)) |
|||
for i := range fileInfoList { |
|||
fmt.Println(fileInfoList[i].Name()) //打印当前文件或目录下的文件或目录名
|
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
package go_to_dir |
|||
|
|||
import ( |
|||
"fmt" |
|||
//"io/ioutil"
|
|||
"log" |
|||
"os" |
|||
"path/filepath" |
|||
) |
|||
|
|||
func main() { |
|||
pwd, _ := os.Getwd() |
|||
|
|||
//获取当前目录下的文件或目录名(包含路径)
|
|||
filepathNames, err := filepath.Glob(filepath.Join(pwd, "*")) |
|||
if err != nil { |
|||
log.Fatal(err) |
|||
} |
|||
|
|||
for i := range filepathNames { |
|||
fmt.Println(filepathNames[i]) //打印path
|
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue