473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Delete hidden files on unix

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

rm .lock*


Mar 3 '08 #1
5 4847
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
Mar 3 '08 #2
loial <jl********@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ünchen
http://mips.gsf.de/staff/pagel
Mar 3 '08 #3
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...in-python.html

regards,
subeen.
http://love-python.blogspot.com
Mar 3 '08 #4
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.
Mar 3 '08 #5
loial <jl********@googlemail.comwrote:
>
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, ti**@probo.com
Providenza & Boekelheide, Inc.
Mar 5 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Powell | last post by:
print_r(is_file("$logPath/$logFileName")); // RETURNS 1 unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED This code should tell me that the file located at...
12
by: hokiegal99 | last post by:
The below code does what I need it to do, but I thought that using something like ext = os.path.splitext(fname) and then searching ext for '.mp3' would be a much more accurate approach to solving...
23
by: da Vinci | last post by:
Greetings, Onwards with the school studying. Working on a program and need to delete a file from a known location on the hard drive but cannot get anything I do to work. I have tried to use...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
1
by: Lenny G. | last post by:
What's the best way to do cross-platform hidden file detection? I want to do something like weed-out the files that should be 'hidden' from os.listdir() (which would be files that start with '.'...
11
by: comp.lang.php | last post by:
Once again, I thought my class method deleteZip() would do the trick, but it never deletes any .zip* file found in a directory: /** * Delete any latent ZIP files found in this album. This...
2
by: Viewer T. | last post by:
I am trying to write a script that deletes certain files based on certain criteria. What I am trying to do is to automate the process of deleting certain malware files that disguise themselves...
36
by: pearl146 | last post by:
Hi, I have some database files (.MDF, .LDF,...) on the server. When I try to delete them, the warning "Cannot delete file: There has been a sharing violation. The source or destination file may...
5
by: fniles | last post by:
I am using VB.NET 2005. When I try to delete a folder that has files underneath it, it gave me "the directory is not empty" error. f = New IO.DirectoryInfo("C:\myfolder") If f.Exists Then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.