Adding a header into multiple .txt files

前端 未结 3 1977
名媛妹妹
名媛妹妹 2021-01-26 05:44

I need a batch file that will add the text \"Write In\" in a new line at the beginning of the content of hundreds of .txt files without removing any existing text. I found somet

3条回答
  •  情深已故
    2021-01-26 06:13

    I would most probably do it like this:

    rem // Create temporary header file:
    > "head.txt" echo Write In
    rem // Iterate all text files in current directory:
    for %%F in ("*.txt") do (
        rem /* Combine header and currently iterated text file into a temporary file;
        rem    there cannot arise any file name conflicts (like temporary files becoming
        rem    iterated also unintendedly, or temporary files overwriting files to handle),
        rem    because the extension of the temporary files differ from the text files: */
        copy /B "head.txt"+"%%~F" "%%~F.tmp"
        rem // Overwrite original text file by temporary file, erase the latter:
        move /Y "%%~F.tmp" "%%~F"
    )
    rem // Erase the temporary header file:
    del "head.txt"
    

提交回复
热议问题