转换绝对路径相对路径在批处理文件 [英] Convert absolute path to relative path in batch file
本文介绍了转换绝对路径相对路径在批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能为绝对路径转换为相对路径在批处理文件? (相反<一href=\"http://stackoverflow.com/questions/1645843/batch-file-resolve-absolute-path-from-relative-path-and-or-file-name\">this).很明显,你将需要两个输入:绝对路径转换,以及您希望它是relativised到绝对参考路径
例如:
路径转换:C:\\文件\\ mynicefiles \\ afile.txt
参考路径:C:\\文件
结果:mynicefiles \\ afile.txt
解决方案
关闭@echo
SETLOCAL EnableDelayedExpansion
设置Path_to_convert = C:\\文件\\ mynicefiles \\ afile.txt
设置Reference_path = C:\\文件
集结果= Path_to_convert:*%Reference_path%\\ =!
回声结果:%结果%
Is it possible to convert an absolute path to a relative path in a batch file? (the opposite of this). Obviously you would need two inputs: the absolute path to convert, and an absolute reference path that you want it to be relativised to.
eg:
Path to convert: c:\documents\mynicefiles\afile.txt
Reference path: c:\documents
Result: mynicefiles\afile.txt
解决方案
@echo off
setlocal EnableDelayedExpansion
set Path_to_convert=c:\documents\mynicefiles\afile.txt
set Reference_path=c:\documents
set Result=!Path_to_convert:*%Reference_path%\=!
echo Result: %Result%
这篇关于转换绝对路径相对路径在批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文