How would one go about deleting all of the directories in a directory tree that have a certain name if the only access to the server available is via FTP?
To clarify, I would like to iterate over a directory tree and delete every directory whose name matches a certain string via FTP. A way to implement this in PHP would be nice – where should I start? Also, if anyone knows of any utilities that would already do this, that would be great as well.
Here is a starting point- a function that will scan through an FTP directory and print the name of any directory in the tree which matches the pattern. I have tested it briefly.
Then do something like this
Unfortunately you can only delete an empty directory with
ftp_rmdir(), but if you look here there is a function calledftp_rmAll()which you could use to remove whole directory structures which you find.Also I have only tested on Unix the trick of using the fail status returned from
ftp_size()as a method of checking if an item returned byftp_nlist()is a directory.