共计 664 个字符,预计需要花费 2 分钟才能阅读完成。
概述
调用 os
包即可。
例子
目录创立
package main
import (
"fmt"
"os"
)
func main() {err := os.Mkdir("/tmp/test_go_main_dir", 0755) // 创立 1 级目录
if err != nil {panic(err)
} else {fmt.Println("/tmp/test_go_main_dir has been created")
}
err = os.MkdirAll("/tmp/test_go_main_dir/1/2/3", 0755) // 创立多级目录
if err != nil {panic(err)
} else {fmt.Println("/tmp/test_go_main_dir/1/2/3 has been created")
}
}
// $ go run main.go
// 输入如下
/**
/tmp/test_go_main_dir has been created
/tmp/test_go_main_dir/1/2/3 has been created
*/
目录删除
package main
import (
"fmt"
"os"
)
func main() {err := os.RemoveAll("/tmp/test_go_main_dir")
if err != nil {panic(err)
} else {fmt.Println("/tmp/test_go_main_dir has been deleted")
}
}
// $ go run main.go
// 输入如下
/**
/tmp/test_go_main_dir/1/2/3 has been deleted
*/
分割我
正文完