我有以下代码:os.path.isdir不返回true
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路径
我试图逃脱,不逸出(即我通过解析SVN的日志的结果获得),许多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
UPDATE
这是代码的一种变通方法版本,但我仍然不能做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
究竟是什么'svn_drive',' svn_repo_path'和'relative_path'。他们是如何产生的?你为什么使用'.encode()'? – 2013-05-08 09:26:41
更新了与该信息的问题 – roundcrisis 2013-05-08 09:29:01
我使用编码,因为我在REPL中尝试相同的东西,它的工作(即isdir返回true) – roundcrisis 2013-05-08 10:19:12