Forum Discussion
Here is VBScript method.
DIM initial_FileCount DIM new_FileCount DIM exists_FileInRecycleBin initial_FileCount = lib_CountFiles("Path to recycle bin") 'Perform Delete operation new_FileCount = lib_CountFiles("Path to recycle bin") exists_FileInRecycleBin = (new_FileCount - initial_FileCount = 1) FUNCTION lib_CountFiles(ByVal fldr_path) DIM fso : SET fso = CreateObject("Scripting.FileSystemObject") Set objFiles = fso.GetFolder(fldr_path).Files lib_CountFiles = objFiles.Count END FUNCTION
Since it is highly unlikely that another process put a new file in the recycle bin, this increase in filecount can be safely assumed to be because of the delete operation you performed.
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.
- djadhav9 years agoRegular Contributor
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
- 2 years ago
- 11 months ago
- 9 years ago
- 8 years ago