I am trying to get a nested for loop to work, however the variable is showing as NULL when the script is executed.
I am trying to pull back a series of files from a CDN. i have managed to use curl to grab a json, and extract the path where the modules are to a text file. My first loop, gets the file path cdn/7220/tiger_20220525T193049Z.bin from the txt file, modules.txt
I will use this in the curl command to grab the file, however i would like to use the file name locally. eg curl -o tiger_20220525T193049Z.bin https://cdn.com/cdn/7220/tiger_20220525T193049Z.bin
I want to use %~nx to do this, however when i use the variable in the second for loop it show as NULL.
SCRIPT
for /f "tokens=*" %%s in (modules.txt) do (
echo %%s
SETLOCAL EnableDelayedExpansion
set FileName=%%s
for %%i in (%FileName%) do set FullPath=%%~nxi
echo %FullPath%
)
OUTPUT
echo cdn/7220/tiger_20220525T201527Z.bin
SETLOCAL EnableDelayedExpansion
set FileName=cdn/7221/trigger_20220525T201527Z.bin
for %i in ((null)) do set FullPath=%~nxi
echo
)
cdn/7220/tiger_20220525T201527Z.bin
ECHO is on.
The second for loop works perfectly if its run stand alone. I have tried to set FileName directly eg FileName=cdn/7220/tiger_20220525T201527Z.bin but it still shows as null.
I thought that by using enableddelayedexpansion would solve this but it has not.