Page 1 of 1

Unable to Delete Empty Folders to Recycle Bin

Posted: Mon Aug 12, 2013 2:57 am
by IdeasVacuum
This code works fine with as many files as are thrown at it:

Code: Select all

Global NewList sgFilesToTrash.s()

               AddElement(sgFilesToTrash())
                          sgFilesToTrash() = "C:\MyTemp\Folder03_EMT"

Procedure ToRecycleBin(*ptrFile)
;--------------------------------

sTemp.s = PeekS(*ptrFile,-1,#PB_UTF8)
Debug "ToRecycleBin(*ptrFile)-->" + sTemp + "<--"

Protected SHFileOp.SHFILEOPSTRUCT
          SHFileOp\pFrom = *ptrFile
          SHFileOp\pTo = #Null
          SHFileOp\wFunc = #FO_DELETE
          SHFileOp\fFlags = #FOF_ALLOWUNDO | #FOF_NOCONFIRMATION ;| #FOF_SILENT

               If SHFileOperation_(@SHFileOp) = 0

                       ProcedureReturn #True
               Else
                       ProcedureReturn #False
               EndIf
EndProcedure

SelectElement(sgFilesToTrash(),0)

*ptrFile = AllocateMemory(StringByteLength(sgFilesToTrash()) + (2 * SizeOf(Character)))
                           PokeS(*ptrFile,sgFilesToTrash(),-1,#PB_UTF8)

Debug "sgFilesToTrash()-->" + sgFilesToTrash() + "<--" ;C:\MyTemp\Folder03_EMT

ToRecycleBin(*ptrFile)
However, if any of the files are (empty) Folders, they do not get deleted to the Recycle Bin.
Error returned: Cannot delete file: Cannot read from the source file or disk.
It's obviously possible to delete folders, so what could be wrong?

Re: Unable to Delete Empty Folders to Recycle Bin

Posted: Wed Aug 14, 2013 6:30 am
by JHPJHP
Windows 7 - 64bit
Windows XP - 32bit

If I understand you correctly:

The folder C:\MyTemp\Folder03_EMT contains some files and an empty folder, and cannot be deleted (due to the empty folder).

I tried the above example, and various other combinations - each one deleted successfully to the Recycle Bin using the posted code.

Probably not any of these... but
Looking beyond the code, this can be experienced if the hard drive has a corruption in that segment - have you tried this from an alternate location. This can also occur if the folder contains a hidden null character, or the rights on the folder don't allow it.

- Try adding a wildcard: "C:\MyTemp\Folder03_EMT*"

Re: Unable to Delete Empty Folders to Recycle Bin

Posted: Wed Aug 14, 2013 3:07 pm
by IdeasVacuum
Thanks for your advice JHPJHP. "C:\MyTemp\Folder03_EMT" is an empty folder and can be deleted manually, so your tests are encouraging. :)

Re: Unable to Delete Empty Folders to Recycle Bin

Posted: Wed Aug 14, 2013 4:42 pm
by IdeasVacuum
Update: Seems there was something wrong with my install of PB5.20 Beta8, the code always works under PB5.20 Beta10.