ich bin mit meinem (kleinen) Latein am Ende und finde den Fehler nicht, warum das Script in 2.7 läuft und in 3.2 nicht...
in der Zeile "33" mit n1 = string.count(rdir,os.sep) kommt die Meldung Objekt hätte Eigenschaft count nicht...??
Hat jemand eine Idee??
Code: Alles auswählen
# Pfade ersetzen #
import sys,os,string
def replace(rdir):
for entry in os.listdir(os.curdir):
if os.path.isdir(entry): # directory; recursive call #
os.chdir(entry)
replace(os.pardir+os.sep+rdir)
os.chdir(os.pardir)
if os.path.isfile(entry): # file; process it... #
ext = os.path.splitext(entry)[1]
if ext == '.htm' or ext == '.html': # ...if HTML source #
nm = entry + ".bak"
if len(sys.argv) > 1:
if sys.argv[1] == "-b":
try:
os.rename(entry,nm) # backup file #
except WindowsError: # backup file already exists #
pass
fin = open(nm,'r')
else:
fin = open(entry,'r')
else:
fin = open(entry,'r')
lines = fin.readlines() # read file #
fin.close()
fout = open(entry,'w')
for line in lines:
c = os.getcwd().split(os.sep) # construct absolute path #
#print(rdir,os.sep)
n1 = string.count(rdir,os.sep)
n2 = len(c) - n1 + 1
cdir = os.sep
for i in range(n2,len(c)):
cdir = os.path.join(cdir,c[i])
cdir = os.path.join(cdir,entry) # --> add file name <-- #
line = string.replace(line,"$LOOK_UP$",rdir)
line = string.replace(line,"$LOOK_HERE$",cdir)
fout.write(line)
fout.close()
if __name__ == '__main__':
print("Start...")
replace("")
print("OK.\n")