On a Windows Command Line, this would produce a new file called test.txt

> echo "hello world" > test.txt

I would like to create a new file AND a new folder in one step. Something like

> echo "hello world" > newFolder\test.txt

But it only produces the error: The system cannot find the path specified.

Is there any chance to avoid using an extra mkdir newFolder?


A quick search and I was unable to find any "trick" but, you can achieve what you want by combining commands on one like like so;

mkdir nested && echo "test" > ./nested/test.txt

Try This:

mkdir folder_name_here && cd folder_name_here/ && echo "hello world" > test.txt

And don't forget to run it IN the directory you want it to save in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.