1

I have a folder containing over 485 Zipped Files. The name of each file has uniform characters with a varying date. I need to do something for files that have the same date. How can I do so? Below is a slice of the file names I have:

Screenshot of the zipped files

I basically need to run a loop through the entire list of files with sub-loops on file numbers that have the same date. How can I do so?

Shai
  • 111,146
  • 38
  • 238
  • 371
Gautham Kanthasamy
  • 219
  • 1
  • 3
  • 11

1 Answers1

1

you can use glob:

import glob
for basefile in glob.glob('*.LOG'):
    for sub_names in glob.glob(basefile+'*'):
        # do your magic here
Shai
  • 111,146
  • 38
  • 238
  • 371
  • Thanks a ton Shai. It works! I am very new to python. So I apologize for asking stupid doubts. Second question: How can I compare the file size between each .LOG files and .LOG.gz_1 files for the same date? I want to be able to use LOG.gz_1 file when both the files sizes are different [on 02/02/2012 for example]? – Gautham Kanthasamy Jul 19 '17 at 15:07
  • @GauthamKanthasamy see [this thread](https://stackoverflow.com/q/2104080/1714410) on getting file size in python. – Shai Jul 20 '17 at 07:53
  • 1
    Thanks @Shai. I sort of did it on my own. :) – Gautham Kanthasamy Jul 20 '17 at 10:05
  • @GauthamKanthasamy that's the best way ;) – Shai Jul 20 '17 at 10:28