Here is some code that could be useful It does not check the
directories for 0 files, but that shouldn't be too difficult to add.
#
from os import listdir, unlink
from os.path import isdir, isfile, islink, join, getmtime
deldir = "C:\Some\Dir"
delF
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
--
http://mail.python.org/mailm
On Apr 9, 1:44 pm, "bahoo" <[EMAIL PROTECTED]> wrote:
> 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 em
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 Ja
Fuzzyman wrote:
> shutil.rmtree
Many thanks. I'll give that a go!
>
> You might need an ``onerror`` handler to sort out permissions.
>
> There is one for just this in pathutils :
>
> http://www.voidspace.org.uk/python/pathutils.html
>
> All the best,
>
> Fuzzyman
> http://www.voidspace.org.u
Tim N. van der Leeuw wrote:
> Wasn't this the example given in the Python manuals? Recursively
> deleting files and directories?
I don't know... I wrote it without consulting anything. Hope I'm not
infringing on a patent :)
--
http://mail.python.org/mailman/listinfo/python-list
Wasn't this the example given in the Python manuals? Recursively
deleting files and directories?
cheers,
--Tim
--
http://mail.python.org/mailman/listinfo/python-list
[rbt]
> What is the most efficient way to recursively remove files and directories?
shutil.rmtree: http://docs.python.org/lib/module-shutil.html#l2h-2356
--
Richie Hindle
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
shutil.rmtree
You might need an ``onerror`` handler to sort out permissions.
There is one for just this in pathutils :
http://www.voidspace.org.uk/python/pathutils.html
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
--
http://mail.python.org/mailman/listinfo/python-lis
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 and get rid of diretories
with rmdir. This works well, but it seems that there should be a more
effic
10 matches
Mail list logo