Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create directory and file in same command using PowerShell

I try to create a folder and a file in one PowerShell command: I tried:

New-Item hello\test\ (New-Item hello\test\file.txt -type file) -type directory -Force

and

New-Item file.txt (New-Item hello\test\ -type direcotry) -type file -Force

But both don't seem to work as expected. What I want to achieve is one command to create hello\test\file.txt

like image 616
DenCowboy Avatar asked Feb 15 '17 09:02

DenCowboy


1 Answers

Just provide the filepath you want, including the directory, and it will work:

New-Item -Path '.\hello\test\file.txt' -ItemType File -Force
like image 77
Martin Brandl Avatar answered Oct 21 '22 01:10

Martin Brandl