In my batch file I scan in a for loop for all .dat files and I need to get the folder names in which these .dat files are located and store them in a variable so I could use it later in this loop. The nested for loop on third line works fine when not in another for loop and I have no idea why it does not work this way. Please help :)
for /f "delims=" %%G in ('dir *.dat /b/s') do (
cd "%%~dG%%~pG"
for /f "delims=" %%A in ('cd') do (
set foldername=%%~nxA
)
echo. Current Folder Name: %foldername%