Find and Delete all files with .xxx extension

Derrick 'dman' Hudson dman at dman13.dyndns.org
Wed Dec 17 21:38:23 CET 2003


On 16 Dec 2003 19:12:34 -0800, hokiegal99 wrote:
> 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:

>> > > 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???

Start by clicking
    Start -> Programs -> Cygwin -> Bash Shell

;-)

> Not everyone has a unix shell,

True.

> and not everyone wants/needs one.

True too.

> None of our users use Linux/Unix.
> They all use Windows XP

That means you are stuck writing simple system management programs for
them because the system doesn't have them out-of-the-box.  It's your
[users'] choice.

> or Mac OS X.

OSX comes with a POSIX shell.

> So, you shouldn't assume that I'm running Linux or some other type
> of Unix.

But you are :-).  OSX is "some other type of Unix".

> I do as an admin/developer, but that's not the point.

Agreed.

> The above python script will run on Windows, Linux, OS X, etc.

Yeah, yeah.  (for such a simple task I'm not impressed, but for
non-trivial stuff (eg more complex "delete all files matching certain
criteria) and the like I would be)

> and it makes for much easier reading.

I think the find(1) example is quite easy reading.  It's one compact
line, with all the detailed file handling taken care of automatically.

> This is a python forum.  So, you're off-topic.

Not really off-topic.  Many times a someone relatively new and/or
inexperienced with computers posts a system admin type of question in
this forum not knowing that the tools already exist.  Pointing out
some existing tools, rather than encouraging reinvention, is never a
bad thing.  Sometimes that education is invaluable for the OP or even
for other lurkers.  If the given solution doesn't apply to your
environment, kindly pass on to the next suggestion or (nicely :-))
clarify if need be.

-D

-- 
[Perl] combines all the worst aspects of C and Lisp: a billion different
    sublanguages in one monolithic executable.
It combines the power of C with the readability of PostScript.
        -- Jamie Zawinski
 
www: http://dman13.dyndns.org/~dman/            jabber: dman at dman13.dyndns.org




More information about the Python-list mailing list