file delete routine is intermittent



Having problems with the following trying to move files to the recycle bin.
It doesn't move all of the files. Any ideas??

Private Function FilesCountAll(sSource As String, sFileType As String) As Long

Dim WFD As WIN32_FIND_DATA
Dim hFile As Long
Dim file2delete As Variant
Dim filenames As New Collection
Dim shf As SHFILEOPSTRUCT
'Start searching for files in sSource by obtaining a file
'handle to the first file matching the filespec passed
hFile = FindFirstFile(sSource & sFileType, WFD)
If hFile <> INVALID_HANDLE_VALUE Then
'must have at least one, so ...
Do
'find the next file and increment the counter
If (Asc(WFD.cFileName) <> vbDot) Then FilesCountAll = FilesCountAll + 1
If (Asc(WFD.cFileName) <> vbDot) Then sFile = sSource & WFD.cFileName & vbNullChar
If (Asc(WFD.cFileName) <> vbDot) Then file2delete = sFile
If (Asc(WFD.cFileName) <> vbDot) Then filenames.Add file2delete
Loop Until FindNextFile(hFile, WFD) = 0
FOF_FLAGS = GetOptionFlags()
For i = 1 To filenames.Count
file2delete = filenames(i)
With shf
.wFunc = FO_DELETE 'action to take place
.pFrom = file2delete 'the file to delete
.fFlags = FOF_FLAGS 'special flags (FOF_*)
End With
Call SHFileOperation(shf)
Next i
End If
'Close the search handle
'and exit the routine if the folder is empty
Call FindClose(hFile)
End Function

The folder location ( sSource ) is determined in another function and verified to exist before this
function is called.
sFileType is set to *.*

The option flags are contained in the getoptionflags function.

tyia


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer


.



Relevant Pages

  • Re: file delete routine is intermittent
    ... WFD.cFileName is a string that includes trailing nulls and padding to the ... So & WFD.cFileName & vbNullChar might result in a string ... Private Function FilesCountAll(sSource As String, sFileType As String) As ... : Dim WFD As WIN32_FIND_DATA ...
    (microsoft.public.vb.winapi)
  • Re: How to start browsing at an existing folder location
    ... For browsing to a folder location I use the following code: ... Public Function BrowseFolder(szDialogTitle As String) As String ... Dim x As Long, bi As BROWSEINFO, dwIList As Long ... Dim szPath As String, wPos As Integer ...
    (comp.databases.ms-access)
  • How to start browsing at an existing folder location
    ... For browsing to a folder location I use the following code: ... Public Function BrowseFolder(szDialogTitle As String) As String ... Dim x As Long, bi As BROWSEINFO, dwIList As Long ...
    (comp.databases.ms-access)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)