我想看看是否存在某些目录。脚本是说它不存在,但我知道它确实存在。
我认为它与以这种格式存储在列表中的字符串有关(双反斜杠): " \\服务器\\ PATH1 \\&#34 + +的env" \\ PATH2"
当我将路径存储到对象中时,它运行正常。 例如 path =" \\ servername \ path1 \ evv \ path2"
import os
x =["env1","env2","env3","env4"]
j=[]
for env in x:
q=r"\\servername\\path1\\"+env+"\\path2"
w=r"\\servername\\path1\\"+env+"\\path2"
e=r"\\servername\\path1\\"+env+"\\path2"
r=r"\\servername\\path1\\"+env+"\\path2"
t=r"\\servername\\path1\\"+env+"\\path2"
y=r"\\servername\\path1\\"+env+"\\path2"
u=r"\\servername\\path1\\"+env+"\\path2"
i=r"\\servername\\path1\\"+env+"\\path2"
o=r"\\servername\\path1\\"+env+"\\path2"
p=r"\\servername\\path1\\"+env+"\\path2"
a=r"\\servername\\path1\\"+env+"\\path2"
s=r"\\servername\\path1\\"+env+"\\path2"
d=r"\\servername\\path1\\"+env+"\\path2"
f=r"\\servername\\path1\\"+env+"\\path2"
g=r"\\servername\\path1\\"+env+"\\path2"
h=r"\\servername\\path1\\"+env+"\\path2"
j.extend((q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h))
for path in j:
if os.path.exists(path):
print "It Exists"
else:
print "It doesnt Exist"
print j
[" \\服务器\ PATH1 \&#34 + +的env" \ PATH2"]
答案 0 :(得分:0)
需要一个for循环来将列表输出为正确的格式
for string in j:
print string
if os.path.exists(string):
print "It Exists"
else:
print "It doesnt Exist"