Rico.JohnnY Posted January 13, 2006 Posted January 13, 2006 As we know %~dp0 is the location of current script,so how to get the parent path of current script?For example:C:\Documents and Settings\Administrator\Desktop\myfolder is the current script dir,and i want to get the parent path(C:\Documents and Settings\Administrator\Desktop), what's the syntax?
xpmaniac4ever Posted January 13, 2006 Posted January 13, 2006 Rico.JohnnY ,C:\Documents and Settings\Administrator\Desktop\myfolder\..\That`s the way I do it !
Rico.JohnnY Posted January 13, 2006 Author Posted January 13, 2006 So what's the syntax while using %~dp0? Set InstPath = %dp0Set InstPath = "%InstPath%\..\"Are these correct?
xpmaniac4ever Posted January 13, 2006 Posted January 13, 2006 Try these:Set InstPath = %dp0Set InstPath2 = "%InstPath%\.."..and tell me if this works
Rico.JohnnY Posted January 13, 2006 Author Posted January 13, 2006 still not workingthe scriptSet InstPath = %~dp0Set InstPath2 = "%InstPath%\.."echo %InstPath2%pauseand the outputC:\Documents and Settings\Administrator\Desktop>Set InstPath = C:\Documents andSettings\Administrator\Desktop\C:\Documents and Settings\Administrator\Desktop>Set InstPath2 = "\.."C:\Documents and Settings\Administrator\Desktop>echoECHO is on.C:\Documents and Settings\Administrator\Desktop>pausePress any key to continue . . .
xpmaniac4ever Posted January 13, 2006 Posted January 13, 2006 (edited) I really don`t know why it doesn`t work for you..hm...try that..without the quotes..so..Set InstPath = %~dp0Set InstPath2 = %InstPath%\....and reply Edited January 13, 2006 by xpmaniac4ever
Rico.JohnnY Posted January 13, 2006 Author Posted January 13, 2006 still with no luck,what i get from InstPath is "\..", but i want the full path:wacko:
jdoe Posted January 13, 2006 Posted January 13, 2006 As we know %~dp0 is the location of current script,so how to get the parent path of current script?For example:C:\Documents and Settings\Administrator\Desktop\myfolder is the current script dir,and i want to get the parent path(C:\Documents and Settings\Administrator\Desktop), what's the syntax?You could do something like that...SET CurrDir=%CD%CD..SET InstPath=%CD%CD %CurrDir%
Rico.JohnnY Posted January 13, 2006 Author Posted January 13, 2006 @jdoeMany thanks..finally works. seems i made things complicated.@xpmaniac4everThanks all the same..
jdoe Posted January 13, 2006 Posted January 13, 2006 orpushd..set parent=%cd%popd@YzöwlThanks for this one. I've never thought PUSHD could be used with ending dots. @Rico.JohnnYIf I were you I would use Yzöwl syntax. Much better
MHz Posted January 15, 2006 Posted January 15, 2006 (edited) %cd% is a poor method to rely on for being the scripts directory as it is the current (working) directory. A batch file called from the registry, as RunOnceEx does, will return C:\ as the current directory.The best solution was mentioned earlier but %~dp0 has a trailing backslash included, so adding another backslash made it fail. Add the below into a batch file and run it and you will show your solution.@echo offcd /d c:\echo.echo Current Working directory is : "%cd%"echo.echo Script directory is : "%~dp0"echo.echo Parent of Script directory is : "%~dp0..\"echo.pauseREM ~ Open explorer in the script's parent directory.explorer.exe "%~dp0..\" Edited January 15, 2006 by MHz
gunsmokingman Posted January 15, 2006 Posted January 15, 2006 Try this VBS script it start a cmd promt that passes the Current Directory to it.Save As ComspecTest.VBSDim CD, Act : Set Act = CreateObject("Wscript.Shell") : CD = Act.CurrentDirectory Act.Run("%Comspec% /c Echo Off && CLS && Color 9e && mode 75,7 && Title Test CDset CD=%" &_ CD & "% && Echo %CD% && Echo %UserName% && set /p = It Worked, Press Any Key To Close")
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now