How to create nested directories using Mkdir in Golang?

前端 未结 5 1295
野趣味
野趣味 2021-01-30 15:33

I am trying to create a set of nested directories from a Go executable such as \'dir1/dir2/dir3\'. I have succeeded in creating a single directory with this line:



        
5条回答
  •  囚心锁ツ
    2021-01-30 15:56

    This way you don't have to use any magic numbers:

    os.MkdirAll(newPath, os.ModePerm)
    

    Also, rather than using + to create paths, you can use:

    import "path/filepath"
    path := filepath.Join(someRootPath, someSubPath)
    

    The above uses the correct separators automatically on each platform for you.

提交回复
热议问题