Windows equivalent of UNIX "touch" command

A fairly standard operation in *nix world is the command touch.  Touch changes file dates, so it's an easy way to kick off backup jobs or similar that use file modification times. Windows doesn't have an exact analogue, but a functionally similar feature exists within PowerShell.

Start a PowerShell command prompt, navigate to the directory where you want to 'touch' the files and enter this command:

 ls * | ForEach-Object {$_.LastWriteTime = Get-Date}


Example of before and after shown below:

    Directory: C:\wd


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       29/12/2017     17:26                2017Scripts
d-----       15/06/2018     14:26                2018Scripts
d-----       16/06/2018     10:07                ArchiveToMerge
d-----       29/05/2018     12:27                Config
d-----       29/05/2018     14:14                Data
d-----       29/05/2018     12:29                Downloads
d-----       23/06/2018     21:25                java
d-----       14/06/2018     11:25                Python
-a----       12/06/2018     10:38         167056 sdelete64.exe


PS C:\wd>  ls * | ForEach-Object {$_.LastWriteTime = Get-Date}
PS C:\wd> dir


    Directory: C:\wd


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       01/07/2018     20:18                2017Scripts
d-----       01/07/2018     20:18                2018Scripts
d-----       01/07/2018     20:18                ArchiveToMerge
d-----       01/07/2018     20:18                Config
d-----       01/07/2018     20:18                Data
d-----       01/07/2018     20:18                Downloads
d-----       01/07/2018     20:18                java
d-----       01/07/2018     20:18                Python
-a----       01/07/2018     20:18         167056 sdelete64.exe


PS C:\wd>

Comments