Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
First off I would like to mention I am using python. I already have a batch file that can do it. I want to know how to do it in python as well. I have done alot of reading and cant come up with the answer. Well I should say without 20 lines of code. Maybe thats how it has to be done but thought I would ask here first. What I have tried is using a wildcard but I keep getting an error.
import os
os.remove("c:/users/xxxx/desktop/new file/*.*")Tried different variations for the wildcard but nothing seems to work. Any help would be greatly appriciated. Also would like to thank ghostdog for all his help in the past. If I cant wildcard all the files in the "new file" folder what about deleting the whole folder?

remove just removes a single file. Try the command help(os). It gives you help on all the functions in that module. You may find listdir or removedirs useful.

Thanks klint it seems windows or at least vista wont let you delete a directory if it has files in it. I think I found what I was looking for. I will post it here maybe it will help someone else. The only trick to get it to work is you have to convert it to a exe with py2exe or you get a windows error in vista. The only thing the exe file does is allow me to run the file with admin privileges. I dont know any way around this if any one could shed some light on it I would appreciate it. Other whise it works perfect. Heres what I found.
import os
for each in os.listdir("c:/Program Files/xxxx/yyyy"): # reads all the files in yos.remove("c:/Program Files/xxxx/yyyy/"+each) # deletes all the files in yos.rmdir("c:/Program Files/xxxx/yyyy") # deletes yWell thats the shortest I could find. Any other ideas would be appreciated.

Glad you got it working. I have not used Vista but have read many people's complaints about difficulties using it due to protection. Perhaps you can try running python.exe with admin privileges?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |