How can I load the contents of a text file into a batch file variable?

前端 未结 6 1735
小鲜肉
小鲜肉 2020-12-07 19:12

I need to be able to load the entire contents of a text file and load it into a variable for further processing.

How can I do that?


Here\'s what I di

6条回答
  •  天涯浪人
    2020-12-07 20:00

    Use for, something along the lines of:

    set content=
    for /f "delims=" %%i in ('filename') do set content=%content% %%i
    

    Maybe you’ll have to do setlocal enabledelayedexpansion and/or use !content! rather than %content%. I can’t test, as I don’t have any MS Windows nearby (and I wish you the same :-).

    The best batch-file-black-magic-reference I know of is at http://www.rsdn.ru/article/winshell/batanyca.xml. If you don’t know Russian, you still could make some use of the code snippets provided.

提交回复
热议问题