How to read input from a file in a batch script


Windows batch scripts are incredibly useful for processing data. You can automate many tasks by a simple batch file. The most common thing that I use is a for loop over all files of a certain file name pattern, often extension:

for %%I in (*.laz) do (
do something with %%I
)

But there are cases where it is required to not loop over all files, but only the files given in a text file, maybe after you have done something in Excel. Luckily, you can also loop through the lines in a file, and even split columns based on a delimiter and treat the individual columns as different arguments. Below script reads from a comma-separated file and uses the first columns as file name for processing with the LAStools command las2las, in this case setting the LAZ version and scaling the intensity.

mkdir fixed
for /F "tokens=1* delims=," %%I in (intensity.csv) do (
las2las -i "%%I" -o "fixed\%%~nxI" -set_version 1.2 -scale_intensity 0.0625
)

Geef een reactie

Uw e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *