Pbs
Content Type
Profiles
Forums
Events
Posts posted by Pbs
-
-
oops, but this fixes that...i ran it in a long name dir, thought it had spaces...
for %%A in ("%~dp0.") do echo %%~nAnobody's perfect...lol
[it *was* 5am when i wrote it! ]
was trying to re-encode my music to my phone in diff dirs and keep the artist\album\song.ext structure..
and just tried this, so if you want to go more than 2 dirs up, use
for %%A in (".\..\..\..") do echo %%~nA
goes up 4 dirs.. etc to go up as many as you want...
or relative to batch file itself:
for %%A in ("%~dp0.\..\..\..") do echo %%~nA
it's:
.=1 file's dir
..=2 parent dir [or.\..]
.\..\..=3 up [the parent dirs parent dir]
.\..\..\..=4 up etc etc..
that one surprised me even..nice n short too..
from cmdline try it out:
for %a in (".\..\..") do echo %~na
[since not starting with a file, no leading .]
was there smart juice in my orange juice this morning or what? lol
yesterday i wrote 24->12hr + am/pm conversion completely inside a sqlite query...
and dude, i've learned so much over the years from you it's silly...thanx so much for sharing...
0 -
i can't believe i can add to the masters both...
for batch file's current dir:
for %%A in ("%~dp0.") do echo %%~nA
i had been using a longer method so i'm killin myself for not seeing yours sooner..
also, for say any file, just add \. to it's path only [for %1 use %p1\.]and use it's name in for loop result..[%~n* ]
so you could have it as a sub-routine and pass paths to it in your batch to get parent dir..[like say,dir of a bunch of mp3s artist dirs
call :getparentdir "d:\path\sub\file.ext"
goto :eof
:getparentdir
for %%A in ("%~dp1.") do echo %%~nA
goto :eofand use .. ["%~dp0.."] to get dir 2dirs up...
my first post..
Enjoy!
[edited to add quotes]
0
retrieve current directory name in batch
in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
Posted
ahh, but 2 diff things, mine is relative to batch file, other is relative to workingdir...
i use a pvr program that runs batches from a diff dir so makes all the diff to me..[always had to work around that]