Create Files and Folders in One Step

by Nov 10, 2010

Use New-Item like this when you want to create a file plus all the folders necessary to host the file:

new-item -type file -force c:\subfolder\anothersubfolder\yetanotherone\test1.txt

This will create the necessary folders first and then insert a blank file into the last folder. You can then edit the file easily using notepad. However, you should watch out as this line will overwrite the file if it already exists. First, you should use Test-Path to check and run the line only if the file is missing.

Twitter This Tip!
ReTweet this Tip!