I am making a search script for parsing log files in archives and am stuck at one particular thing I didnt find resources anywhere else.
I need to somehow replace the “id1” of this string for “anything”. Simply put I want the script to take anything in that particular place in path. Is this possible only by using logZip as one huge regex?
logZip = ("c:/logs/" + str(id1) + "/" + str(id2) + "/" + str(id1) + "_log_" + str(dateID) + "_" + str(hourID) + "-00_" + str(id2) + ".zip")
As requested, Im adding a sample paths and files I want to define:
c:/logs/aaa1/sss2/aaa1_log_2013-01-14-13-00_sss2.zip
c:/logs/aaa2/sss2/aaa2_log_2013-01-14-13-00_sss2.zip
c:/logs/aaa3/sss2/aaa3_log_2013-01-14-13-00_sss2.zip
Next step will be to make the same thing with sss2 part.
returns a list of complete paths to files where
id1is replaced by a wildcard*.os.path.joinmakes the path construction clearer.If
logZiphas to be a single file, you can useglob.iglob, which returns an iterator: