Can I create folders as part of New-Item with new files

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 6 years, 4 months ago.

  • Author
  • #5036

    by willsteele at 2012-08-22 19:04:21

    I often iterate over collections and want to know if I can create folders as a part of a New-Item cmdlet. For instance, if I have a folder C:\test, but, I want to create a file in C:\test\new\folder I have to create the new and folder folders before I can create the new file. Is there a command or set of switches I can use to automatically create folders in a file path without having to first create the folders?

    by Geoff Guynn at 2012-08-22 19:22:48

    I used this and it worked.

    New-Item -Path "c:\test1\test2\test.txt" -ItemType file -force

    by poshoholic at 2012-08-23 07:33:22

    Geoff has it right. Invoking New-Item with the -Force is the prescribed way of doing this.

    by willsteele at 2012-08-23 07:34:42

    I know it was a simple question, it just eluded me. Thanks folks. I appreciate the quick, succinct replies.

You must be logged in to reply to this topic.