区别"%〜DP0"和"。\\"? [英] Difference between "%~dp0" and ".\"?

查看:316
本文介绍了区别"%〜DP0"和"。\\"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说我使用一个批处理文件,并希望它直接到位于批次的同一目录下的文件夹。如果我没看错,你会写%〜DP0 \\ whateverfoldername。但可以通过只是写不一样的做。\\ whateverfoldername?如果是这样,相应的命令的差异和/或优势是什么?


解决方案

  PUSHD%〜DP0

经常被用于改变从所述批料开始原来的目录。
这是当用户可以以管理员身份运行,这改变当前目录为你新的操作系统的非常有用的!尝试它的某个时候。只要一个简单的蝙蝠

 关闭@echo
echo.CD =%CD%
PUSHD%〜DP0
echo.CD =%CD%
暂停

现在运行它。
现在,再次运行作为管理员在Vista,Win 7的,运8,2008 Server或2012服务器。
看看会发生什么?

Let's say I'm using a batch file and want it to direct to a folder located in the same directory of the batch. If I'm not wrong you would write "%~dp0\whateverfoldername". But can't the same done by just writing ".\whateverfoldername"? If so, what is the difference and/or advantage of the respective command?

解决方案

pushd %~dp0

is often used to change to the original directory from which the batch was started. This is very useful in newer OS's when the user may 'Run as administrator' which changes the current directory for you! Try it sometime. Just make a simple bat

@echo off
echo.CD=%CD%
pushd %~dp0
echo.CD=%CD%
pause

Now run it. Now run it again 'As Administrator' on Vista, Win 7, Win 8, 2008 Server, or 2012 Server. See what happens?

这篇关于区别"%〜DP0"和"。\\"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆