I need to get the name of the directory for each file with extension *.txt within specified folder/directory (including its subfolders/subdirectories).
I've tried the solution from here: Parent folder from full path
But it looks like that set "myPath=%%~Pa"
doesn't do anything in the code below:
@echo off
cd /d "F:\Game\"
for /r %%f in (*.txt) do (
echo file: %%f
set "myPath=%%~Pa"
echo myPath: %myPath%
for %%a in ("%myPath:~0,-1%") do (
set "myParent=%%~Na"
echo %myParent%
)
)
pause.
For these files:
F:\Game\file1.txt
F:\Game\first_subfolder\file2.txt
F:\Game\first_subfolder\hellothere\file3.txt
F:\Game\first_subfolder\hellothere\lala\file4.txt
I expect to get the name of the directory for each of them:
Game
first_subfolder
hellothere
lala
How to get the name of the directory for each text file in directory tree?