Wednesday, 5 June 2019

windows - Equivalent of Linux `touch` to create an empty file with PowerShell?



In PowerShell is there an equivalent of touch?


For instance in Linux I can create a new empty file by invoking:


touch filename

On Windows this is pretty awkward -- usually I just open a new instance of notepad and save an empty file.


So is there a programmatic way in PowerShell to do this?


I am not looking to exactly match behaviour of touch, but just to find the simplest possible equivalent for creating empty files.



Answer



Using the append redirector ">>" resolves the issue where an existing file is deleted:


echo $null >> filename

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...