2 Methods to Clear Contents of a File on Windows

2 Methods to Clear Contents of a File on Windows

In Windows, can be needed to clear the contents of a file without deleting file itself. One of the fastest ways to achieve it, by running command.

Create a file for testing:

echo Hello world> test.txt

Method 1 - CMD

We can use break command to clear contents of a file:

break>test.txt

Method 2 - PowerShell

PowerShell can be used as well to clear contents of a file. Use Clear-Content command as follows:

Clear-Content test.txt

Leave a Comment

Cancel reply

Your email address will not be published.