Find and Delete all files with .xxx extension

hokiegal99 hokiegal99 at hotmail.com
Tue Dec 16 22:12:34 EST 2003


William Park <opengeometry at yahoo.ca> wrote in message news:<brntu1$5c6a8$1 at ID-99293.news.uni-berlin.de>...
> 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 ...

What would you man on a Windows box??? Not everyone has a unix shell,
and not everyone wants/needs one. None of our users use Linux/Unix.
They all use Windows XP or Mac OS X. So, you shouldn't assume that I'm
running Linux or some other type of Unix. I do as an admin/developer,
but that's not the point. The above python script will run on Windows,
Linux, OS X, etc. and it makes for much easier reading. This is a
python forum. So, you're off-topic.




More information about the Python-list mailing list