Skip to content

Instantly share code, notes, and snippets.

@rsarrazin2
Created October 18, 2024 15:05
Show Gist options
  • Save rsarrazin2/6fad352e3e85003ee0b7c55d5eea11d6 to your computer and use it in GitHub Desktop.
Save rsarrazin2/6fad352e3e85003ee0b7c55d5eea11d6 to your computer and use it in GitHub Desktop.
Batch file to collect lines from a file into a space-separated list stored into a variable exported to the call site
@echo off
rem Required to expand the list at every for step
setlocal enabledelayedexpansion
rem Reference: https://stackoverflow.com/a/33824457/1945549
set "list="
for /f "delims=" %%i in (%~dp0\local_file) do set list=!list! %%i
rem Pattern required to export variable to the call site
endlocal & set list=%list%
rem Just for debugging, not required
echo %list%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment