WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinInet
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Removing Empty Directories with FTP


Question:

Has anyone put together some code to recursively remove empty directories using ftp. I have been using iftpfindnext() to remove the files, but iftpfindnext returns "" if the directory patch contains no files. So, I end up with my files deleted, with a directory tree that is empty.

I know that Iftpdirremove will remove the directory. When you recurse the directory with iftpfindnext it gives you the names of the files recursively. Any directories that are empty never get returned. Therefore I don't know about them and can't issue the iftpdirremove.

I was wondering how I could move through the directories and remove them you have to do them one at a time. I actually thought I could do it with iftpfindnext.

Answer:

The WinInet extender does not give you the names of empty directories. If you manage to get an empty directory that you want to delete... well the extender cannot help you.

However if you have a directory tree that you want to delete, and every directory has a file in it, then you can simply make a list of directories to delete later.

So as you delete files, save off the directories into a list, then when done deleting files, delete the directories IN REVERSE ORDER.

Alternatively, you could use the iFtpCmd function to do a 'ls' and parse the output then use iFtpDirRemove.


Article ID:   W16378
File Created: 2005:02:18:12:20:06
Last Updated: 2005:02:18:12:20:06