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

后端 未结 19 2251
一整个雨季
一整个雨季 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:26

    in cmd window type:

    type nul > your_file.txt
    

    This will create 0 bytes in your_file.txt file.

    Another way of doing it is by using the echo command:

    echo.> your_file.txt
    

    echo. - will create a file with one empty line in it.

    Edited on 2019-04-01:

    If you need to preserve the content of the file use >> instead of >

    >   Creates a new file
    >>  Preserves content of the file
    

    Example

    type nul >> your_file.txt
    

    Edited on 2020-04-07

    You can also use call command.

    Calls one batch program from another without stopping the parent batch program. The call command accepts labels as the target of the call.

    Example:

    call >> your_file.txt
    

提交回复
热议问题