如何编码接受文件作为参数并打印完整路径的Python脚本?获取参数的完整路径
E.g.
~/.bin/python$ ls
./ ../ fileFinder.py test.md
~/.bin/python$ py fileFinder.py test.md
/Users/theonlygusti/.bin/python/test.md
~/.bin/python$ py fileFinder.py /Users/theonlygusti/Documents/Online/theonlygusti.github.io/index.html
/Users/theonlygusti/Documents/Online/theonlygusti.github.io/index.html
所以,应该找相关文件,test.md
,并通过绝对路径/Users/theonlygusti/Downloads/example.txt
给出的文件也绝对路径的绝对路径。
如何制作上面的脚本?
鉴于目前可与相同的基本名称不同的目录多个文件,你不能这样做。您只需遍历每个驱动器上的每个目录,并为每个使用匹配的基本名称找到的文件生成目录路径。 – TigerhawkT3
'os.path.abspath'会做的伎俩... – mgilson
@ TigerhawkT3你错了,这是没有意义的 – theonlygusti