批量标准化文件路径 [英] Normalize file path in batch
本文介绍了批量标准化文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以从绝对文件路径中批量解析.
?例如,以下批处理脚本应输出 C:\ Users \ xyz \ other \ abc.txt
:
Is there a way to resolve the ..
from an absolute file path in batch? For example, the following batch script should output C:\Users\xyz\other\abc.txt
:
REM Project dir is an absolute path, for example, C:\Users\xyz\project\
SET projectDir=%~1
REM Target file is a path relative to the project dir, for example, ..\other\abc.txt
SET target=%~2
REM Concatenate paths. This becomes C:\Users\xyz\project\..\other\abc.txt
SET absoluteTarget=%projectDir%%target%
SET absoluteTargetClean=...
echo %absoluteTargetClean%
absoluteTarget
变量引用现有文件.
我需要相同的目录而不是文件.您可以使用相同的方法来实现这一目标吗?
I need the same for a directory instead of the file. Can you use the same way to achieve that?
推荐答案
我想知道,谁能想到一个像 C:\ Users \ xyz \ project \ .. \ other \ abc.txt这样的路径?
,但我们开始:
I wonder, how anyone ever could come up with a path like C:\Users\xyz\project\..\other\abc.txt
, but here we go:
SET "absPath=C:\Users\xyz\project\..\other\abc.txt"
for %%i in ("%absPath%") do SET "absPathClean=%%~fi"
echo %absPathClean%
适用于文件和文件夹.
有关更多信息,请咨询以获得/?
For more information, consult for /?
这篇关于批量标准化文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文