ファイル/ディレクトリの作成

レジストリアクセス(2) - PowerShell Memoでは「new-item」を利用してレジストリキーを作成するサンプルを紹介しました。
「new-item」はファイル/ディレクトリの作成も可能です。

ディレクトリの作成(存在しないディレクトリは再帰的に作成)

MSH C:\> $path = "D:\Doc\MSH\Test\Test"
MSH C:\> new-item -Path $path -Type directory


    Directory: FileSystem::D:\Doc\MSH\Test


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        2005/10/19      0:13            Test

ファイルの作成

MSH C:\> $path = "D:\Doc\MSH\Test\Test\test.txt"
MSH C:\> new-item -Path $path -Type file


    Directory: FileSystem::D:\Doc\MSH\Test\Test


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        2005/10/19      0:14          0 test.txt