Author |
Topic: Folder Deletes (Read 642 times) |
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Folder Deletes
« Thread started on: Jan 16th, 2015, 8:44pm » |
|
I want a simple way to delete a folder and all its sub-folders and files. A folder browser program comes with LB4.04, but there is no delete capability. There is another LB program that does browse and has a delete capability, but no way to set the starting point - it always starts at the root directory, and it takes a while to get the folder you want to delete.
Does anyone here know of an API or dll or program that can be called from LB to delete a folder? It should accept the passed folder name, ask "Are you sure", and move the folder to the recycle bin.
It is my understanding that re-naming a file can, in effect, move it to the recycle bin by changing the catalog. Is that correct?
LB4 can only re-name files, not folders. What about BBC basic?
Any other ideas or suggestions?
r.m.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Folder Deletes
« Reply #1 on: Jan 16th, 2015, 10:43pm » |
|
on Jan 16th, 2015, 8:44pm, Alincon wrote:Does anyone here know of an API or dll or program that can be called from LB to delete a folder? |
|
The API you want is SHFileOperation which is documented at MSDN here:
http://msdn.microsoft.com/en-gb/library/windows/desktop/bb762164.aspx
It's not difficult to call from LB4/LBB:
Code:sub DeleteFolder folder$
struct shfo, hwnd as ulong, wFunc as ulong, pFrom as ptr, pTo as ptr, _
fFlags as ulong, fAnyOperationsAborted as long, _
hNameMappings as ulong, lpszProgressTitle as ptr
confirm "Are you sure?"; answer$
if answer$ <> "yes" then exit sub
FO.DELETE = 3
FOF.ALLOWUNDO = 64
shfo.wFunc.struct = FO.DELETE
shfo.pFrom.struct = folder$ + chr$(0)
shfo.fFlags.struct = FOF.ALLOWUNDO
calldll #shell32, "SHFileOperationA", shfo as struct, res as long
if res then notice "File or folder could not be deleted"
end sub (although called DeleteFolder, this will move files to the Recycle Bin just as well).
Quote:LB4 can only re-name files, not folders. What about BBC basic? |
|
LBB can rename folders using NAME. I hadn't realised that LB4 can't, but it appears to be true.
Richard.
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Re: Folder Deletes
« Reply #2 on: Jan 17th, 2015, 01:20am » |
|
The API call works fine. The folder is moved to the recycle bin. Also, there is a built-in "are you sure", so these lines are not needed.
Code:
confirm "Are you sure?"; answer$
if answer$ <> "yes" then exit sub
Thank you very much.
r.m.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Folder Deletes
« Reply #3 on: Jan 17th, 2015, 10:01am » |
|
on Jan 17th, 2015, 01:20am, Alincon wrote:Also, there is a built-in "are you sure", so these lines are not needed. |
|
Be careful; I got no 'built-in' confirmation here (Windows 8.1). If you always want the user to confirm, do it in your code and add the FOF_NOCONFIRMATION flag so you don't get two requests.
Richard.
|
|
Logged
|
|
|
|
|