Okay, I am new to Python. I really like it, by the way.
I need to be pointed in the right direction. I need to empty a directory. There will be files, and sub-directories that also need to be emptied.
I took a look at os.rmdir('c:/foo') but if there are files in it, you get an error message.
So obviously, you have to remove() files, one by one. When I use os.listdir('c:/foo'), it lists everything - files and directories. You could use this to get a list of the files, but you would have directories in there, too. So you have to put in some isdir() or isfile() in there.
I bet there is an efficient way to do this. I am sure someone has witten code for this before. Do you have it? Is it in a book? Is it in the documentation, and I have missed it? I really think it is silly to re-invent the wheel.
Thanks for your help.
I need to be pointed in the right direction. I need to empty a directory. There will be files, and sub-directories that also need to be emptied.
I took a look at os.rmdir('c:/foo') but if there are files in it, you get an error message.
So obviously, you have to remove() files, one by one. When I use os.listdir('c:/foo'), it lists everything - files and directories. You could use this to get a list of the files, but you would have directories in there, too. So you have to put in some isdir() or isfile() in there.
I bet there is an efficient way to do this. I am sure someone has witten code for this before. Do you have it? Is it in a book? Is it in the documentation, and I have missed it? I really think it is silly to re-invent the wheel.
Thanks for your help.