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
#1
I script in bash and some expect and I am trying to make the move to python.
I have taken a beginner class at a local community college and am now trying to put "it" to use.
The best way for me to do so is to look at what I have written in bash and expect and rewrite in python.


I am working at a Centos Linux VM command line
Python 2.6.6 (I know old and crusty)

So my question :
Quote:#!/usr/bin/python
import glob, os
for f in glob.glob("*.err"):
os.remove(f)

The snip of code works well to delete any file with an extension of ".err".
For instance, I want to be able to delete any file with an extension of .err and the extension of .log

The python equivalent to the Linux command line :
Quote:rm *.log *.err

Thanks in advance !!
Reply


Messages In This Thread
Delete multiple files using file extention - by sumncguy - Jan-22-2019, 12:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python convert multiple files to multiple lists MCL169 6 1,566 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  splitting file into multiple files by searching for string AlphaInc 2 907 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 1,180 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 974 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Find duplicate files in multiple directories Pavel_47 9 3,144 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  delete all files and subdirectory from a main folder mg24 7 1,636 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  delete all files which contains word sql_Table1 mg24 2 873 Sep-15-2022, 10:05 PM
Last Post: mg24
  Delete multiple lines from txt file Lky 6 2,311 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Delete empty text files [SOLVED] AlphaInc 5 1,579 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,250 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