Find files in a variable (original) (raw)

Hi mate,

I need your help. I have python 3.x and I need to find files with two variables in the path variable

path = "transaction.log." + date + "_*." + str(output1) + "*"

For example I need to find files with
transaction.log.2025-02-19_03.sd-a703-937d.gz
transaction.log.2025-02-19_04.sd-a703-937d.gz

What Do i need to modify in the path variable to look for these files.

Now I find all files, because i put “_*” from a date.

Regards

JamesParrott (James Parrott) April 24, 2025, 8:21am 2

>>> import glob
>>> glob.glob(f'transaction.log.2025-02-19_??.sd-a703-937d.gz')
['transaction.log.2025-02-19_03.sd-a703-937d.gz', 'transaction.log.2025-02-19_04.sd-a703-937d.gz']
>>>

Ivan3 (Silva) April 24, 2025, 1:10pm 3

Hi James

How to feed

path = “transaction.log.” + date + “_*.” + str(output1) + “*”

where “_*.” i need to change “*” by a variable that for example look for 2 value like 03 and 04 and not all files with the same date.how would it be?

Thanks a lot James for your help!

Regards

JamesParrott (James Parrott) April 24, 2025, 1:40pm 4

I’m not sure but try:

f'transaction.log.{date}_0[2-4].{str(output1)}*.gz'

The glob syntax is described here. glob — Unix style pathname pattern expansion — Python 3.13.3 documentation

Ivan3 (Silva) April 24, 2025, 11:51pm 5

Thanks James! For your help. I can move fordward.
The option run!