Re: recursively removing files and directories

2007-04-09 Thread Sick Monkey
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

Re: recursively removing files and directories

2007-04-09 Thread Eli Criffield
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

Re: recursively removing files and directories

2007-04-09 Thread Eli Criffield
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

recursively removing files and directories

2007-04-09 Thread bahoo
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

Re: recursively removing files and directories

2006-01-16 Thread rbt
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

Re: recursively removing files and directories

2006-01-16 Thread rbt
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

Re: recursively removing files and directories

2006-01-16 Thread Tim N. van der Leeuw
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

Re: recursively removing files and directories

2006-01-16 Thread Richie Hindle
[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

Re: recursively removing files and directories

2006-01-16 Thread Fuzzyman
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

recursively removing files and directories

2006-01-16 Thread rbt
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