Windows equivalent of 'touch' (i.e. the node.js way to create an index.html)

后端 未结 19 2362
一整个雨季
一整个雨季 2020-11-28 00:47

On a windows machine I get this error

\'touch\' is not recognized as an internal or external command, operable program or batch file.

19条回答
  •  孤街浪徒
    2020-11-28 01:20

    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.

提交回复
热议问题