On Mar 3, 9:38 am, subeen <tamim.shahr...@gmail.comwrote:
On Mar 3, 6:13 pm, Philipp Pagel <pDOTpa...@helmholtz-muenchen.de>
wrote:
loial <jldunn2...@googlemail.comwrote:
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.