我有以下代码:
path = os.path.join(svn_drive, svn_repo_path, relative_path)
if os.path.isdir(path.encode('string-escape')):
print path, " is a directory"
else:
print path, " is not a directory"
这导致以下结果:
D:\mysvn\trunk\Assets\myfile.max is not a directory
D:\mysvn\\Animations is not a directory
....
即问题在于它os.path.isdir
似乎没有认识到它path
实际上是一个目录的事实
svn_drive
D:
svn_repo_path
在这种情况下是驱动器号 在这种情况下mysvn
relative path
是相对于 svn repo 的路径(我通过解析 svn log 的结果获得)
我尝试了转义,而不是转义,许多os.path
方法(abspath
,,basename
等),但似乎没有任何效果:(
我也接受替代方案;),我只是想知道一条路径,然后通过电子邮件发送文件,并不介意如何(我知道有时人们想保留他们的代码,但这只是一个独立的脚本)
我还需要在稍后阶段打开文件以通过电子邮件发送它,我得到一个找不到的文件,我猜想从这里开始
完整的功能列表(如果有帮助):
def parse_svn_results(lines, svn_drive, svn_repo_path):
result = []
for x in lines.split("\n"):
if "trunk/" in x:
relative_path = x.lstrip('MDA ').replace("/","",1).replace("/", os.sep)
path = os.path.join(svn_drive, svn_repo_path, relative_path)
if os.path.isdir(path.encode('string-escape')):
print path, " is a directory"
else:
print path, " is not a directory"
result.append(path)
return result
更新
这是代码的解决方法版本,但我仍然做不到imghdr.what(filename)
(filename
结果中的文件之一在哪里)
def parse_svn_results(lines, svn_drive, svn_repo_path):
result = []
for x in lines.split("\n"):
if "trunk/" in x:
relative_path = x.lstrip('MDA ').replace("/", "", 1).replace("/", os.sep)
temp_path = os.path.join(svn_drive, os.sep, svn_repo_path, relative_path)
path = format_path(temp_path)
if path is not None:
result.append(path)
return result
def format_path(file_destination):
file_name = os.path.basename(file_destination)
path = os.path.dirname(file_destination)
base, ext = os.path.splitext(file_name)
picture_format = None
e = ext if picture_format is None else '.%s' % picture_format.lower()
if e:
to_path = os.path.join(path, base + e)
return to_path