[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Delete hidden files on unix

loial

3/3/2008 11:57:00 AM

How can I delete hidden files on unix with python, i.e I want to do
equivalent of

rm .lock*






8 Answers

Peter Otten

3/3/2008 12:04:00 PM

0

loial wrote:

> How can I delete hidden files on unix with python, i.e I want to do
> equivalent of
>
> rm .lock*

>>> for fn in glob.glob(".lock*"):
.... os.remove(fn)
....

Peter

Philipp Pagel

3/3/2008 12:14:00 PM

0

loial <jldunn2000@googlemail.com> wrote:
> How can I delete hidden files on unix with python, i.e I want to do
> equivalent of

> rm .lock*

Here is one way to do it:

import os, glob
for filename in glob.glob('.lock*'):
os.unlink(filename)


Alternatively, you could also do this:

import os
os.system('rm .lock*')


cu
Philipp

--
Dr. Philipp Pagel
Lehrstuhl f. Genomorientierte Bioinformatik
Technische Universität München
http://mips.gsf.de/s...

subeen

3/3/2008 2:38:00 PM

0

On Mar 3, 6:13 pm, Philipp Pagel <pDOTpa...@helmholtz-muenchen.de>
wrote:
> loial <jldunn2...@googlemail.com> wrote:
> > How can I delete hidden files on unix with python, i.e I want to do
> > equivalent of
> > rm .lock*
>
> Here is one way to do it:
>
> import os, glob
> for filename in glob.glob('.lock*'):
> os.unlink(filename)
>
> Alternatively, you could also do this:
>
> import os
> os.system('rm .lock*')
>
> cu
> Philipp
>
> --
> Dr. Philipp Pagel
> Lehrstuhl f. Genomorientierte Bioinformatik
> Technische Universität Münchenhttp://mips.gsf.de/s...

Another way is to execute the linux command directly :)
Check here: http://love-python.bl.../2008/02/execute-linux-commands-in-p...

regards,
subeen.
http://love-python.bl...

sjdevnull@yahoo.com

3/3/2008 7:20:00 PM

0

On Mar 3, 9:38 am, subeen <tamim.shahr...@gmail.com> wrote:
> On Mar 3, 6:13 pm, Philipp Pagel <pDOTpa...@helmholtz-muenchen.de>
> wrote:
>
>
>
> > loial <jldunn2...@googlemail.com> wrote:
> > > How can I delete hidden files on unix with python, i.e I want to do
> > > equivalent of
> > > rm .lock*
>
> > Here is one way to do it:
>
> > import os, glob
> > for filename in glob.glob('.lock*'):
> > os.unlink(filename)
>
> > Alternatively, you could also do this:
>
> > import os
> > os.system('rm .lock*')
>
> > cu
> > Philipp
>
> > --
> > Dr. Philipp Pagel
> > Lehrstuhl f. Genomorientierte Bioinformatik
> > Technische Universität Münchenhttp://mips.gsf.de/s...
>
> Another way is to execute the linux command directly :)
> Check here:http://love-python.blogspot.com/2008/02/execute-linux-comma......
>

Note that that can get dangerous with shell expansions:

e.g. (don't run in a directory with files you want to keep!)
import os
open("--help", "w")
os.system("rm *help")

will actually run "rm --help", printing the help for rm rather than
removing the file named "--help". There are a lot of security
implications to allowing this kind of shell expansion of commands.
The system-call method with os.unlink is easier to get right.

Tim Roberts

3/5/2008 7:49:00 AM

0

loial <jldunn2000@googlemail.com> wrote:
>
>How can I delete hidden files on unix with python, i.e I want to do
>equivalent of
>
>rm .lock*

What did you try? I'm curious to know what you tried that didn't work,
because I can't think of any obvious solution to this that would not just
work.

You did try to solve this yourself before sending a message around the
world, didn't you?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

The Chief Instigator

4/2/2008 5:17:00 AM

0

On Tue, 1 Apr 2008 22:03:04 -0700 (PDT), Tom N <simpleman.s43@gmail.com> wrote:
> On Apr 1, 8:30 pm, Scientology is a cult <Y...@ema.yil> wrote:
>> Gerry Armstrong <ge...@gerryarmstrong.org> wrote innews:ph16v3plf43aumkjc8jitk9set97ruumth@4ax.com:

>> > ? Gerry Armstrong
>> >http://www.gerryarm...

>> Gerry,
>> The Commodore says you're a fucking asshole. ;)

> He's an example of what happens to people who fuck with other
> people. They seldom take it lying down.

....while you whine at everything, Alan.

> The CoS wins, even if it loses. The hoops they are forcing him
> to jump through, the money it is costing him, the time and effort...

You mean the money the Co$ isn't getting because a larger audience is
laughing at Dead Hubbard's hallucinations.

> Those of you with some remnant of intelligence remaining will
> learn a lesson here, and back off.

Why? Anyone can push your buttons, boy. You demonstrate that
multiple times daily.

> And don't give me any of this "free speech" crap. That only applies
> to people who limit themselves to the truth.

....and the truth is that Lafayette Ronald Hubbard was a compulsive
liar for the majority of his life. (He died with his fat ass shot
full of Vistaril, remember?)

> Don't expect me to read your reply. It will surely be as stupid
> as the statement above. You trolls are boring as hell and as
> predictable as clocks. Cuckoo clocks.
>
> "Tom Newton"

If you don't read any critics' followups, how did you know what they
said that put you in the straitjacket you're begging for?

--
Patrick "The Chief Instigator" Humphrey (patrick@io.com) Houston, Texas
chiefinstigator.us.tt/aeros.php (TCI's 2007-08 Houston Aeros) AA#2273
LAST GAME: Milwaukee 4, Houston 3 (SO, March 30)
NEXT GAME: Wednesday, April 2 at Lake Erie, 6:05



Tom N

4/2/2008 5:55:00 AM

0

On Apr 1, 10:03 pm, Tom N <simpleman....@gmail.com> wrote:
> On Apr 1, 8:30 pm, Scientology is a cult <Y...@ema.yil> wrote:
>
> > Gerry Armstrong <ge...@gerryarmstrong.org> wrote innews:ph16v3plf43aumkjc8jitk9set97ruumth@4ax.com:
>
> > > ¸ Gerry Armstrong
> > >http://www.gerryarm...
>
> > Gerry,
>
> > The Commodore says you're a fucking asshole. ;)
>
> He's an example of what happens to people who fuck with other
> people. They seldom take it lying down.
>
> The CoS wins, even if it loses. The hoops they are forcing him
> to jump through, the money it is costing him, the time and effort...
>
> Those of you with some remnant of intelligence remaining will
> learn a lesson here, and back off.
>
> And don't give me any of this "free speech" crap. That only applies
> to people who limit themselves to the truth.
>
> Don't expect me to read your reply. It will surely be as stupid
> as the statement above. You trolls are boring as hell and as
> predictable as clocks. Cuckoo clocks.
>
> Tom Newton

And note that he isn't anonymous anymore.
"Chief In...."
Same dipshit troll. Posting more shit that I'll never see.
Thinks he's accomplishing something.

I'm here, punk. I post what I want and I don't read your
shit. Or any replies to it. No matter what name you are
cowering behind with your tail between your legs where
your balls should be.

What are you going to do about it? Post more shit I don't
read? That no one with any power reads?

Oh golly, I am just trembling in my boots.

How's my butthole taste, little boy?

Tom Newton









The Chief Instigator

4/2/2008 7:25:00 AM

0

On Tue, 1 Apr 2008 22:54:38 -0700 (PDT), Tom N <simpleman.s43@gmail.com> wrote:
> On Apr 1, 10:03 pm, Tom N <simpleman....@gmail.com> wrote:
>> On Apr 1, 8:30 pm, Scientology is a cult <Y...@ema.yil> wrote:

>> > Gerry Armstrong <ge...@gerryarmstrong.org> wrote innews:ph16v3plf43aumkjc8jitk9set97ruumth@4ax.com:

>> > > ? Gerry Armstrong
>> > >http://www.gerryarm...

>> > Gerry,
>> > The Commodore says you're a fucking asshole. ;)

>> He's an example of what happens to people who fuck with other
>> people. They seldom take it lying down.

>> The CoS wins, even if it loses. The hoops they are forcing him
>> to jump through, the money it is costing him, the time and effort...
>> Those of you with some remnant of intelligence remaining will
>> learn a lesson here, and back off.
>> And don't give me any of this "free speech" crap. That only applies
>> to people who limit themselves to the truth.

>> Don't expect me to read your reply. It will surely be as stupid
>> as the statement above. You trolls are boring as hell and as
>> predictable as clocks. Cuckoo clocks.
>>
>> Tom Newton

> And note that he isn't anonymous anymore.
> "Chief In...."
> Same dipshit troll. Posting more shit that I'll never see.
> Thinks he's accomplishing something.

I am...making you act like the brainless paranoid you are, Alan, since
I'm not even involved in this thread, yet you're mentioning my
identity, which has included my real name in every .signature.

> I'm here, punk. I post what I want and I don't read your
> shit. Or any replies to it. No matter what name you are
> cowering behind with your tail between your legs where
> your balls should be.

I'm anything but anonymous, Co$ Coward "Tom Newton".

> What are you going to do about it? Post more shit I don't
> read? That no one with any power reads?
> Oh golly, I am just trembling in my boots.
> How's my butthole taste, little boy?

If you're supposedly not seeing anything I post, why are you
complaining, Alan? FLUNK!

--
Patrick "The Chief Instigator" Humphrey (patrick@io.com) Houston, Texas
chiefinstigator.us.tt/aeros.php (TCI's 2007-08 Houston Aeros) AA#2273
LAST GAME: Milwaukee 4, Houston 3 (SO, March 30)
NEXT GAME: Wednesday, April 2 at Lake Erie, 6:05