LB Booster
« Folder Deletes »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:49am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Folder Deletes  (Read 642 times)
Alincon
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 147
xx 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
User IP Logged

Alincon
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 147
xx 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls