How to delete files with long file names
Posted on 2006-05-24
I'm using the FileSystemObject in VB6 and am having problems deleting lots of folders, some of which contain files with very long names.
Just for illustration, assume I have (not my actual code, but this shows the problem):
Dim sFolder as string
Dim sFile as string
sFolder = "\\server\share\folder\"
sFile = sFolder & "XXX.txt"
(where XXX is a very long series of characters such that len(sFile) > 256)
Dim oFS as new FileSystemObject
This causes a "Path not Found" error. I can understand why - although the filename sFile is not used directly by my code, FSO clearly tries to delete each file in the folder in turn before deleting the folder. Note that oFS.FileExists(sFile) give the answer FALSE, which is clearly wrong!!!
Anyway, I have a lot of these folders, but only some have the issue. How can I elegantly delete folders with this problem?