473,667 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4863
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(".loc k*"):
.... os.remove(fn)
....

Peter
Mar 3 '08 #2
loial <jl********@goo glemail.comwrot e:
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('.loc k*'):
os.unlink(filen ame)
Alternatively, you could also do this:

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

--
Dr. Philipp Pagel
Lehrstuhl f. Genomorientiert e 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...@helm holtz-muenchen.de>
wrote:
loial <jldunn2...@goo glemail.comwrot e:
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('.loc k*'):
os.unlink(filen ame)

Alternatively, you could also do this:

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

cu
Philipp

--
Dr. Philipp Pagel
Lehrstuhl f. Genomorientiert e 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...@helm holtz-muenchen.de>
wrote:
loial <jldunn2...@goo glemail.comwrot e:
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('.loc k*'):
os.unlink(filen ame)
Alternatively, you could also do this:
import os
os.system('rm .lock*')
cu
Philipp
--
Dr. Philipp Pagel
Lehrstuhl f. Genomorientiert e 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********@goo glemail.comwrot e:
>
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
6464
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 $logPath/$logFileName should delete the log file, however, it never deletes it due to permissions error. However, upon checking the file properties I find this:
12
7958
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 this problem. Could someone demonstrate how to search ext for a specific string? This script works great for deleting illegal music on user machines ;) Thanks!!!
23
8936
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 the remove function that is included with <cstdio> but cannot get it to work properly. My reference book has the following....
16
17004
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 must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
1
2020
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 '.' under Unix, files that have the hidden attribute set on windows, and whatever it is that makes Mac files hidden). Is there a util or lib that does this for me? Thanks, Gary
11
5788
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 method is to be inherited by all listing classes to allow for * list-wide deletion of latent server-created ZIP files for security purposes *
2
9272
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 as system files and hidden files. When I use os.remove() after importing the os module is raises a Windows Error: Access denied probably because the files have disguised themselves as system files. Is there anway to get adequate privileges under...
36
5089
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 be in use." appears. Since I am new to the environment I don't know where the files come from and where they might be used.
5
33151
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 f.Delete() --error "the directory is not empty" End If How can I delete a folder with files underneath it ? Thank you.
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8367
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8889
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7391
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2781
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.