![]() ![]() ![]() Now let’s run the script and observe the output: C:\Batchography>read-line-by-line.batĭid you notice something missing? Yes, line 3 is not displayed and that’s because empty lines are skipped by design. Note how line 3 is left intentionally blank. Let’s see the contents of the-file.txt: Line 1 Replace the variable name “ a” and the input text file “ the-file.txt” with your file and variable name. Here’s the specific FOR /F syntax needed to read the Batch files line by line: offįor /f "delims=" %%a in (the-file.txt) DO ( In Batch files, to open and read files, you have to use the FOR /F switch which is usually used to tokenize the input it receives. If you want to capture the output into a variable, just update the action: for /f i in ('printappdir') do set RESULTi echo The directory is RESULT If the command has multiple lines of output, then this will end up saving only the last line, since previous lines get overwritten by subsequent iterations. In this article, I am going to show you how to read a text file line by line using the Batch files scripting language.įor more advanced Batch scripting topics, please grab a copy of the Batchography book. This is yet another article about Batch files. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |