473,385 Members | 2,180 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,385 software developers and data experts.

recursively removing files and directories

Hi,

I found a message on Jan 16, 2006 regarding the same topic, except
that I wanted to remove only certain files that satisfy the format
"ABC_XXX_XXX.dat", but not the other files. Once the files are
removed, if a folder becomes empty, I want to remove the folder as
well.

The solution to the Jan 16 2006 message required many lines of python
code. I was wondering if there is a simpler solution to my problem at
hand, perhaps by using more specialized functions?

Thanks!
bahoo

Apr 9 '07 #1
2 2540
On Apr 9, 1:44 pm, "bahoo" <b83503...@yahoo.comwrote:
Hi,

I found a message on Jan 16, 2006 regarding the same topic, except
that I wanted to remove only certain files that satisfy the format
"ABC_XXX_XXX.dat", but not the other files. Once the files are
removed, if a folder becomes empty, I want to remove the folder as
well.

The solution to the Jan 16 2006 message required many lines of python
code. I was wondering if there is a simpler solution to my problem at
hand, perhaps by using more specialized functions?

Thanks!
bahoo
Something like

import os
import re

def processFiles(args,dir,fileList):
for thisFile in fileList:
if re.match(r'REGEXPATTERN',thisFile):
os.unlink("%s%s"dir,thisFile)

os.path.walk("/",processFiles,None)

But thats just off the top of my head, so that mite not be exact.

Eli Criffield

Apr 9 '07 #2
Forgot the rmdir

import os
import re

def processFiles(args,dir,fileList):
for thisFile in fileList:
if re.match(r'REGEXPATTERN',thisFile):
os.unlink("%s%s"dir,thisFile)
os.rmdir(dir)

os.path.walk("/",processFiles,None)

Eli Criffield

Apr 9 '07 #3

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

Similar topics

4
by: Ruby Tuesday | last post by:
Is there a fast way to read files/directory recursively? Instead of inspecting each file(s)/dir(s), is there a way to know that its a file or a directory from its hidden attribut both for windows...
1
by: Trinity | last post by:
Hi, I want to delete a particular file in all the sub-directories. I am using the SHFileOperation() API. But it is not deleting the files recursively. Any sample code is appreciated. TIA
1
by: Antonio Lopez Arredondo | last post by:
hi all !!! I need to copy a folder and its subfolders to another location; which class should I use ? could only find the System.IO.Directory.MOVE but don't know how to COPY. thanks in...
5
by: rbt | last post by:
What is the most efficient way to recursively remove files and directories? Currently, I'm using os.walk() to unlink any files present, then I call os.walk() again with the topdown=False option...
3
by: Kamen TOMOV | last post by:
Hi, Is uploading recursively directories to a web server possible with JavaScript? I mean is it possible read a directory recursively and dynamically construct <input type="file"> with value...
2
by: Rahul83 | last post by:
Hi.. I'm new to Perl programming. I need to compare two directories of similar structure... check all the subdirectories in it and generate a report of the changes in the files in all the...
1
by: ArchanaAshok | last post by:
Hi All, I have done a script to compare 2 similar directories containing equal number of files, and to compare the content of those files in the directories. But there is some problem in the...
9
by: bhumikas | last post by:
Hi all, I need a help in perl script.The basic idea is,it must have command line arguments for the user flexibility.the files are in the format as shown below. MainFolder Directory ...
8
by: Anil Gupte | last post by:
Hi all! Hope you can help me. I want to find all files matching a wildcard in all subdirectories. Is there a quick way to do that? For example in DOS I can go dir *.txt /s and it will find...
1
by: kumarboston | last post by:
Hi all, I am trying to copy couple of directories and their files to another place. Each directory have 25-30 files and numbered accordingly, the problem I am facing is, I have to copy files...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.