Python Forum
Delete multiple files using file extention
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete multiple files using file extention
#2
As far as i am aware i dont think there is a way to return multiple hits with glob.

use zip to iterate over both
for f1,f2 in zip(glob.glob('*.err'), glob.glob('*.log')):
    os.remove(f1)
    os.remove(f2)
or for a shorter for loop header
err = glob.glob('*.err')
log = glob.glob('*.log')

for f1,f2 in zip(err, log):
    os.remove(f1)
    os.remove(f2)
or just use a function
def remove_files(ext):
    for f in glob.glob(ext):
        os.remove(f)
        
remove_files('*.err')
remove_files('*.log')
Recommended Tutorials:
Reply


Messages In This Thread
RE: Delete multiple files using file extention - by metulburr - Jan-22-2019, 02:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python convert multiple files to multiple lists MCL169 6 1,629 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  splitting file into multiple files by searching for string AlphaInc 2 938 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 1,224 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 985 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Find duplicate files in multiple directories Pavel_47 9 3,221 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  delete all files and subdirectory from a main folder mg24 7 1,661 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  delete all files which contains word sql_Table1 mg24 2 889 Sep-15-2022, 10:05 PM
Last Post: mg24
  Delete multiple lines from txt file Lky 6 2,360 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Delete empty text files [SOLVED] AlphaInc 5 1,624 Jul-09-2022, 02:15 PM
Last Post: DeaD_EyE
  rename and add desire "_date" to end of file name before extention RolanRoll 1 1,270 Jun-13-2022, 11:16 AM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020