How can I save a file in a directory that does not exist?
In other words, it would have to automatically create the directory/sub-directories (if it does not exist) and then save the file to it.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Everyone provided an answer, but forgot to turn the recursive flag on. You must specify mkdir’s third argument to true, to create directory tree (from mkdir manual):