mkdir() says theres no such directory and fails?

It happens because you don’t have images/listing-images/rent path existing in your filesystem. If you want to create the whole path – just pass the 3rd argument as a true: mkdir(‘images/listing-images/rent/’.$insertID, 0777, true); There is also a chance you’re in a wrong directory currently. If this is the case – you need to change the current … Read more

Recursive mkdir() system call on Unix

There is not a system call to do it for you, unfortunately. I’m guessing that’s because there isn’t a way to have really well-defined semantics for what should happen in error cases. Should it leave the directories that have already been created? Delete them? What if the deletions fail? And so on… It is pretty … Read more

Vim: Creating parent directories on save

augroup BWCCreateDir autocmd! autocmd BufWritePre * if expand(“<afile>”)!~#’^\w\+:/’ && !isdirectory(expand(“%:h”)) | execute “silent! !mkdir -p “.shellescape(expand(‘%:h’), 1) | redraw! | endif augroup END Note the conditions: expand(“<afile>”)!~#’^\w\+:/’ will prevent vim from creating directories for files like ftp://* and !isdirectory will prevent expensive mkdir call. Update: sligtly better solution that also checks for non-empty buftype and … Read more

How to create nested directories using Mkdir in Golang?

os.Mkdir is used to create a single directory. To create a folder path, instead try using: os.MkdirAll(folderPath, os.ModePerm) Go documentation func MkdirAll(path string, perm FileMode) error MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that … Read more

mkdir if not exists using golang

Okay I figured it out thanks to this question/answer import( “os” “path/filepath” ) newpath := filepath.Join(“.”, “public”) err := os.MkdirAll(newpath, os.ModePerm) // TODO: handle error Relevant Go doc for MkdirAll: MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. … If path is already a … Read more