Reputation: 713
I'm walking through the file tree for all files
FOR /R "N:/somewhere/far/away/" %%A IN (.) DO (
Pushd %%A
Echo now in %%A
)
"Echo now in" will say N:/somewhere/far/away/0001 for example.
How can i get just the 0001 part of this variable for use elsewhere.
Thanks
Upvotes: 0
Views: 105
Reputation: 41234
Give this a run:
@echo off
FOR /D /R "N:\somewhere\far\away\" %%A IN (*) DO (
Pushd "%%A"
Echo now in "%%~nxA"
popd
)
Upvotes: 2
Reputation: 5197
You could add another for loop that looks at the path as a string in %%A
and grabs the name of last directory -
setLocal enableDelayedExpansion
FOR /R "N:/somewhere/far/away/" %%A IN (.) DO (
FOR /F "delims=\" %%B in ("%%~pA") do set dir=%%B
Pushd %%A
Echo now in !dir!
)
Upvotes: 0