Get working/batch/file dirs from one line[any dir of it's path too!]
here's a little tool to use from batch files, how to get the current dir only, or any level of it's path.. [2 dirs up,3 up, 4 etc] not the whole path, just one part...so if in c:\winnt\system32: "for %%A in ("..") do @echo %%~nA" would echo "winnt" [one . would =system32]
Code:
for %%A in ("[color=blue]..\..\..\..[/color]") do set dir4upworking=%%~nA
@echo %dir4upworking%
or relative to batch file itself:
Code:
for %%A in ("[color=blue]%~dp0\[COLOR="deepskyblue"]..\..\..\..[/color][/COLOR]") do set dir4upbat=%%~nA
echo %dir4upbat%
it's:
.= file's/current dir [or ".\" ]
..=1 up, parent dir [or ".\.."]
..\..=2 up [the parent dirs parent dir] [or ".\..\.."]
..\..\..=3 up etc etc..
that one surprised me..nice n short too..
from cmdline try it out:
Code:
for %a in (".\..") do @echo %~na
for %a in ("%~dpn0\..\..") do @echo %~na
use "set somevar=" in place of echo to use it for real in batches..
can be used to say, keep your dir structure when copying/encoding files to another location, among other things..
basically, easy relative paths for batches..
Enjoy
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie