[英]Normalize file path in batch
有沒有一種方法可以從絕對文件路徑中批量解析..
? 例如,以下批處理腳本應輸出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
變量引用現有文件。
我需要相同的目錄而不是文件。 您可以使用相同的方法來實現嗎?
我想知道,誰能想到一個像C:\\Users\\xyz\\project\\..\\other\\abc.txt
這樣的路徑,但是我們去了:
SET "absPath=C:\Users\xyz\project\..\other\abc.txt"
for %%i in ("%absPath%") do SET "absPathClean=%%~fi"
echo %absPathClean%
適用於文件和文件夾。
有關更多信息,請咨詢for /?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.