转换绝对路径为相对路径给出使用bash当前目录 [英] Convert absolute path into relative path given a current directory using Bash
本文介绍了转换绝对路径为相对路径给出使用bash当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
绝对=/富/栏
电流=/富/巴兹/富# 魔法相对=../../栏
如何创建魔法(希望不是太复杂code ...)?
解决方案
$蟒蛇-c进口os.path中;打印os.path.relpath('/富/酒吧', /富/巴兹/富')
给出了:
../../酒吧
Example:
absolute="/foo/bar"
current="/foo/baz/foo"
# Magic
relative="../../bar"
How do I create the magic (hopefully not too complicated code...)?
解决方案
$ python -c "import os.path; print os.path.relpath('/foo/bar', '/foo/baz/foo')"
gives:
../../bar
这篇关于转换绝对路径为相对路径给出使用bash当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文