Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Delete hidden files on unix

Reply
Thread Tools

Delete hidden files on unix

 
 
loial
Guest
Posts: n/a
 
      03-03-2008
How can I delete hidden files on unix with python, i.e I want to do
equivalent of

rm .lock*






 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      03-03-2008
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
 
Reply With Quote
 
 
 
 
Philipp Pagel
Guest
Posts: n/a
 
      03-03-2008
loial <> 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/staff/pagel
 
Reply With Quote
 
subeen
Guest
Posts: n/a
 
      03-03-2008
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/staff/pagel


Another way is to execute the linux command directly
Check here: http://love-python.blogspot.com/2008...in-python.html

regards,
subeen.
http://love-python.blogspot.com
 
Reply With Quote
 
sjdevnull@yahoo.com
Guest
Posts: n/a
 
      03-03-2008
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/staff/pagel

>
> Another way is to execute the linux command directly
> Check here:http://love-python.blogspot.com/2008...ommands-in-pyt...
>


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.
 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a
 
      03-05-2008
loial <> 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,
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate Hidden field on post back and retrieve value from Hidden Field Rick ASP .Net 3 04-13-2010 05:38 PM
Win 7 folders hidden despite 'show hidden' checked Boppy NZ Computing 10 01-23-2010 02:56 AM
PHP/Perl/Unix Virus: delete config.php files asap Ignoramus6539 Perl Misc 2 08-30-2006 08:22 PM
How would I discover the text in a block element hidden by overflow:hidden style being set? SolarCanine Javascript 2 09-20-2005 06:27 PM
Command or script to delete hidden files on ftp? Jason Priest Perl Misc 2 01-08-2005 11:30 AM



Advertisments