Find and Delete all files with .xxx extension

William Park opengeometry at yahoo.ca
Tue Dec 16 16:37:06 EST 2003


Heike C. Zimmerer <usenet03q2 at hczim.de> wrote:
> William Park <opengeometry at yahoo.ca> writes:
> 
> > hokiegal99 <hokiegal99 at hotmail.com> wrote:
> >> import os, string
> >> setpath = raw_input("Enter the path: ") #This can be hard coded.
> >> for root, dirs, files in os.walk(setpath, topdown=False):
> >>      for fname in files:
> >>          s = string.find(fname, '.mp3')
> >>          if s >=1:
> >>              fpath = os.path.join(root,fname)
> >>              os.remove(fpath)
> >>              print "Removed", fpath, "\n"
> >
> > FYI, in shell, you would go
> >     find . -type f -name '*.mp3' | xargs rm
> 
> Which will fail if the file name contains any spaces or other special
> characters (not too unusual for .mp3 - Files).

In which case, you look up 'man find xargs' and edit the command to
    find ... -print0 | xargs -0 ...

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data management and processing. 




More information about the Python-list mailing list