Mi objetivo es verificar si un o varios archivos existen. Esto lo intento por medio de un ciclo for que vaya creciendo de uno en uno el numero i, y que forme parte de el string el nombre del archivo que quiero validar si existe o no. Intente pasar el número por str(). Pero aun así me da el error de que no se puede concatenar int con str. Si nuevo en esto, si noten otro error el código agradecería que me corrigieran. Gracias de antemano. :)
import os
import sys
linelengt_userconfig = 99
charlengt_userconfig = 99
search = "0"
alreadysetsearch = False
filelog = "0"
alreadysetfile = False
perm = "0"
alreadysetperm = False
alreadyfile = True
while alreadyfile == True:
for i in range(charlengt_userconfig):
if os.path.isfile("C:/Program Files/logsearcher100/log" + "(" + str(i) + ")"):
alreadyfile = True
else:
namefinallog = "log" + "(" + i + ")"
searchend = False
print("Usage: ")
print(" COMMAND INFO. ")
print(" set search Set the string to search in the file.")
print(" set file Set the file to use")
print(" set perm Set the permissions that will have the file")
print(" set finallog Set the file that will have the info collected")
print(" run Run the script once you have of the options set")
print(" quit Stop the script")
while keepgoing == True:
usage = str(input("$ "))
if usage == "set search":
search = str(input("SEARCH: "))
alreadysetsearch = True
if usage == "set file":
filelog = str(input("PATH/FILE: "))
alreadysetfile = True
if usage == "set perm":
perm = str(input("PERMISSIONS: "))
alreadysetperm = True
if usage == "set finallog":
namefinallog = str(input("FINAL LOG PATH/NAME: "))
if usage == "run" and alreadysetfile == True and alreadysetperm == True:
keepgoing = False
run()
if usage == "run" and (alreadysetsearch == False or alreadysetfile == False or alreadysetperm == False):
print("Cant run the script, not all values are set. Please set all the values required.")
if usage == "quit":
sys.exit()
usefullfile = open(filelog,perm)
runintext(search,file,perm,finallog)
def runintext():
global search,file,perm,finallog
placechar = 0
placeline = 0
for placeline in usefullfile(filelog,perm):
for x in range(linelengt_userconfig):
if search in placeline:
finallog = open(namefinallog,"rw")
writelines = finallog.write("line: " + placeline)
for i in range(charlengt_userconfig):
if search in (placeline[(placechar + i):(placechar + len(search) + i)]):
finallog.seek(len(writelines) + 1)
finallog.write("char(s): " + (placechar + i) + ":" + (placechar + len(search) + i))
searchend = True
else:
finallog.write("no match found")
searchend = True
if searchend == True:
scriptinfo.close()
Escribo esto por que me dice que mi pregunta es mayormente código, así besos por donde orinan y bendiciones xD :)