Rico.JohnnY Posted January 13, 2006 Share 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? Link to comment Share on other sites More sharing options...
xpmaniac4ever Posted January 13, 2006 Share Posted January 13, 2006 Rico.JohnnY ,C:\Documents and Settings\Administrator\Desktop\myfolder\..\That`s the way I do it ! Link to comment Share on other sites More sharing options...
Rico.JohnnY Posted January 13, 2006 Author Share Posted January 13, 2006 So what's the syntax while using %~dp0? Set InstPath = %dp0Set InstPath = "%InstPath%\..\"Are these correct? Link to comment Share on other sites More sharing options...
xpmaniac4ever Posted January 13, 2006 Share Posted January 13, 2006 I guess so. Link to comment Share on other sites More sharing options...
Rico.JohnnY Posted January 13, 2006 Author Share Posted January 13, 2006 not working..any idea? Link to comment Share on other sites More sharing options...
xpmaniac4ever Posted January 13, 2006 Share Posted January 13, 2006 Try these:Set InstPath = %dp0Set InstPath2 = "%InstPath%\.."..and tell me if this works Link to comment Share on other sites More sharing options...
Rico.JohnnY Posted January 13, 2006 Author Share 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 . . . Link to comment Share on other sites More sharing options...
xpmaniac4ever Posted January 13, 2006 Share 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 Link to comment Share on other sites More sharing options...
Rico.JohnnY Posted January 13, 2006 Author Share Posted January 13, 2006 still with no luck,what i get from InstPath is "\..", but i want the full path:wacko: Link to comment Share on other sites More sharing options...
jdoe Posted January 13, 2006 Share 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% Link to comment Share on other sites More sharing options...
Rico.JohnnY Posted January 13, 2006 Author Share Posted January 13, 2006 @jdoeMany thanks..finally works. seems i made things complicated.@xpmaniac4everThanks all the same.. Link to comment Share on other sites More sharing options...
Yzöwl Posted January 13, 2006 Share Posted January 13, 2006 orpushd..set parent=%cd%popd Link to comment Share on other sites More sharing options...
jdoe Posted January 13, 2006 Share 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 Link to comment Share on other sites More sharing options...
MHz Posted January 15, 2006 Share 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 Link to comment Share on other sites More sharing options...
gunsmokingman Posted January 15, 2006 Share 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") Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now