Skip to content

Instantly share code, notes, and snippets.

@anzeljg
Last active July 3, 2019 07:16
Show Gist options
  • Save anzeljg/d916d10ff0ad035822b0118a60a93d1f to your computer and use it in GitHub Desktop.
Save anzeljg/d916d10ff0ad035822b0118a60a93d1f to your computer and use it in GitHub Desktop.
implementation of 'touch' command on Windows
Windows does not natively include a touch command.
You can use any of the available public versions or you can use your own version.
Save this code as touch.cmd and place it somewhere in your path.
@echo off
setlocal enableextensions disabledelayedexpansion
(for %%a in (%*) do if exist "%%~a" (
pushd "%%~dpa" && ( copy /b "%%~nxa"+,, & popd )
) else (
type nul > "%%~fa"
)) >nul 2>&1
It will iterate over it argument list, and for each element if it exists, update the file timestamp, else, create it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment