I want to delete all files in a WebDav directory with pyCurl. I was able to delete one specific file with the following code:
def filedelete(url, filename, upload_user, upload_pw):
c = pycurl.Curl()
url = url + filename
c.setopt(pycurl.URL, url)
c.setopt(pycurl.CUSTOMREQUEST, "DELETE")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.USERPWD, upload_user + ":" + upload_pw)
c.perform()
c.close()
For my understanding it is not possible to use wildcards in curl. So the only solution for this task is to read a list of all files in this directory and delete every file. How can I read the list of files and is it possible to send a list of filenames/urls with one command to reduce the load on the server?
Thanks in advance!
I was able to create a solution by myself with the following functions. Perhaps it is not the most elegant solution but it is working for me.
The function
filedeletedeletes all files on the WebDav Urlurl. For this the function calls first the functionlistfiles. This function creates an array of all files and folders on theurl. After that each file is deleted individually in the functionfiledelete.