如何设置父目录的Windows上的路径的变量? [英] How to SET a variable to the path of parent directory on windows?
问题描述
带命令行的再挣扎,我必须弄清楚,我可以在一个变量保存当前工作目录,像这样:
Struggling with command line again, I have figure out that I can store the current working directory in a variable like so:
SET current=%cd%
我将如何设置父关系吗? SET父=%..%
不起作用,因为它呼应%..%
How would I set parent though? SET parent=%..%
does not work, as it echoes %..%
基本上,调用批处理脚本 C:\\ A \\ B \\ myscript.bat
包含以下内容:
Basically, calling a batch script C:\a\b\myscript.bat
with the following contents:
@echo off
set current=%cd%
echo %current%
打印 C:\\ A \\ B
和我想的设置的变量父
,以便它打印 C:\\ A
无需改变当前的工作目录 ..
prints C:\a\b
and I should like to set a variable parent
so that it would print C:\a
without changing the current working directory to ..
这可能吗?
推荐答案
上移一个目录,想起了电流,设置父,然后弹出下来的目录,回到你开始的地方。
Move up a directory, remembering the current, set the parent, and then pop down a directory, back to where you started
@echo off
set current=%cd%
pushd ..
set parent=%cd%
popd
echo current %current%
echo parent %parent%
这篇关于如何设置父目录的Windows上的路径的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!