How to Create an Empty File Using PowerShell


You can use the following syntax to create an empty file using PowerShell:

New-Item c:\users\bobbi\data1\new_data.txt -type file

This particular example creates an empty text file named new_data.txt in the path specified.

The following example shows how to use this syntax in practice.

Example: How to Create an Empty File Using PowerShell

Suppose that we have a directory with the following path:

  • c:\users\bobbi\data1

We can type Dir to list out all files in this directory:

Suppose that we would like to create a new empty file named new_data.txt and add it to this folder.

We can use the following syntax to do so:

New-Item c:\users\bobbi\data1\new_data.txt -type file

The following screenshot shows how to use this syntax in practice:

PowerShell create empty file

We can see that we were able to successfully create a new file named new_data.txt and that it has a Length of 0, which indicates that it is an empty file with no content.

If we use the Dir statement once again, we can see that this new empty file has been added to the folder that we specified:

We can see that the empty file named new_data.txt does indeed exist in this folder.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Rename File Extension of Multiple Files
PowerShell: How to List Files in Directory by Date
PowerShell: How to Copy and Rename a File

Leave a Reply