检查cmd shell中的两个变量是否指向同一文件夹的可靠方法 [英] A reliable way to check if two variables in a cmd shell point to the same folder
本文介绍了检查cmd shell中的两个变量是否指向同一文件夹的可靠方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不能仅通过比较以下变量来检查它:
It can't be checked just by comparing these variables:
C:\>set "d1=C:\"
C:\>set "d2=C:\Windows\.."
C:\>if %d1%==%d2% (echo true) else (echo false)
false
我可以用pushd
和popd
以及其他变量组成一个复杂的结构,但是没有简单的方法吗?
I can make up a sophisticated construct with pushd
and popd
and additional variables but isn't there a simpler way?
推荐答案
类似于jeb的解决方案,但是使用FOR而不是调用子例程
Similar to jeb's solution, but using FOR instead of called subroutine
for %%A in ("%d1%") do for %%B in ("%d2%") do if "%%~fA"=="%%~fB" (echo true) else (echo false)
这篇关于检查cmd shell中的两个变量是否指向同一文件夹的可靠方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文