本文整理汇总了Python中ntpath.commonprefix方法的典型用法代码示例。如果您正苦于以下问题:Python ntpath.commonprefix方法的具体用法?Python ntpath.commonprefix怎么用?Python ntpath.commonprefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ntpath
的用法示例。
在下文中一共展示了ntpath.commonprefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_commonprefix
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import commonprefix [as 别名]
def test_commonprefix(self):
tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
"/home/swen")
tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
"\\home\\swen\\")
tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
"/home/swen/spam")
示例2: do_cd
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import commonprefix [as 别名]
def do_cd(self, line):
p = line.replace('/','\\')
oldpwd = self.pwd
newPath = ntpath.normpath(ntpath.join(self.pwd,p))
if newPath == self.pwd:
# Nothing changed
return
common = ntpath.commonprefix([newPath,oldpwd])
if common == oldpwd:
res = self.findPathName(ntpath.normpath(p))
else:
res = self.findPathName(newPath)
if res is None:
logging.error("Directory not found")
self.pwd = oldpwd
return
if res.isDirectory() == 0:
logging.error("Not a directory!")
self.pwd = oldpwd
return
else:
self.currentINode = res
self.do_ls('', False)
self.pwd = ntpath.join(self.pwd,p)
self.pwd = ntpath.normpath(self.pwd)
self.prompt = self.pwd + '>'
示例3: do_cd
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import commonprefix [as 别名]
def do_cd(self, line):
p = string.replace(line,'/','\\')
oldpwd = self.pwd
newPath = ntpath.normpath(ntpath.join(self.pwd,p))
if newPath == self.pwd:
# Nothing changed
return
common = ntpath.commonprefix([newPath,oldpwd])
if common == oldpwd:
res = self.findPathName(ntpath.normpath(p))
else:
res = self.findPathName(newPath)
if res is None:
logging.error("Directory not found")
self.pwd = oldpwd
return
if res.isDirectory() == 0:
logging.error("Not a directory!")
self.pwd = oldpwd
return
else:
self.currentINode = res
self.do_ls('', False)
self.pwd = ntpath.join(self.pwd,p)
self.pwd = ntpath.normpath(self.pwd)
self.prompt = self.pwd + '>'