github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/internal/pcscommand/cd.go (about) 1 package pcscommand 2 3 import ( 4 "fmt" 5 "github.com/qjfoidnh/BaiduPCS-Go/baidupcs" 6 "github.com/qjfoidnh/BaiduPCS-Go/internal/pcsconfig" 7 ) 8 9 // RunChangeDirectory 执行更改工作目录 10 func RunChangeDirectory(targetPath string, isList bool) { 11 pcs := GetBaiduPCS() 12 err := matchPathByShellPatternOnce(&targetPath) 13 if err != nil { 14 fmt.Println(err) 15 return 16 } 17 18 data, err := pcs.FilesDirectoriesMeta(targetPath) 19 if err != nil { 20 fmt.Println(err) 21 return 22 } 23 24 if !data.Isdir { 25 fmt.Printf("错误: %s 不是一个目录 (文件夹)\n", targetPath) 26 return 27 } 28 29 GetActiveUser().Workdir = targetPath 30 pcsconfig.Config.Save() 31 32 fmt.Printf("改变工作目录: %s\n", targetPath) 33 34 if isList { 35 RunLs(".", nil, baidupcs.DefaultOrderOptions) 36 } 37 }