Forum Discussion
Thanks for the code snippet. I tried using the count method when I first approached this problem, but it appears that when you delete a file, there are other items that are also placed into the recycle bin at the same time. So, for example, the count before deleting a file could be 15, you delete 1 item from disk, and the new could would be 17. Deleting one more file could cause the count to go to 20. It is an unreliable approach.
I can see why it can seem like an unreliable method. Although as we can see that since the number of files produced in the recycle bin is unpredictable, an increase in file count is a highly accurate indication that file was deleted from somewhere.
For more accurate verification, we can use the file size. What do you think of this?
DIM fso : SET fso = CreateObject("Scripting.FileSystemObject") DIM exists_FileInRecycleBin DIM objFile, fileSize objFile = fso.GetFile({FilePath}) fileSize = objFile.size 'Perform Delete operation exists_FileInRecycleBin = lib_FindFileBySize({Path to recycle bin}, fileSize) FUNCTION lib_FindFileBySize(ByVal fldr_path, ByVal byt_fileSize) lib_FindFileBySize = FALSE DIM objFiles , obj_file Set objFiles = fso.GetFolder(fldr_path).Files For Each obj_file in objFiles IF obj_file.size = CLng(byt_fileSize) THEN lib_FindFileBySize = TRUE EXIT FOR END IF Next END FUNCTION
Related Content
- 10 months agoIrinaManea
- 8 years agomfoster711
- 8 years agozsousa
Recent Discussions
- 23 hours agojstaehlin