Results 1 to 2 of 2

Thread: Function Recycle (to move filesystem-objects into the bitbucket)

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174

    Function Recycle (to move filesystem-objects into the bitbucket)

    API:
    Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (Byval pFileOp As Dword) As Long
    
    Thinbasic-function:
    '######################################################################################################################    
       ' recycles files and folders ( means to move those into the garbage-can )
      
    '######################################################################################################################    
    function Recycle(byval sPath         as string,                                        
            optional byval bNeed2Confirm as Boolean ) as boolean                                                                     
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
       
        ' sPath      
        '           can be any { filename | directory | wildcard }-combination
        '            e.g., "C:\Data\*\R*me.txt" 
        ' bNeed2Confirm 
        '            if TRUE, a dialog will show up and ask the user to confirm the action alike
        '           "Do you really want to move the file xy into the recycling-bin ?" [YES] [NO]
        '            if FALSE, it is done silently without any sign of action
        ' returns:
        '          TRUE if succesful
        '          FALSE if failed (due to lack of privilege, read-only-media etc) 
        
     
        string szPath, sBuffer
        Long l = 32
    '......................................................................................................................
        if rightf$(sPath, 1) = "\" then 
            szPath = Utf8ToAnsi$(leftf$(sPath,lenf(sPath)-1)) & $NUL
        else 
            szPath = Utf8ToAnsi$(sPath) & $NUL
        endif 
        
        while l < lenf(szPath)
            l += l
        wend 
        if lenf(szPath) < l then szPath &= repeat$(l - lenf(szPath), $NUL)
                                                                
        sBuffer = mkdwd$(0, 3, strptr(szPath), 0) & _
                  MKWRD$(iif(bNeed2Confirm, 64,  80)) & _
                  MKDWD$(0, 0, 0)
             
        SHFileOperation( strptr(sBuffer) ) 
           
        function = File_Exists(sPath) xor true 
        
            
    '......................................................................................................................
        
        end function 
    '======================================================================================================================
    
    Last edited by ReneMiner; 13-11-2023 at 17:42.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    Great example of what programmer can code in thinBasic.
    Thanks Renč

    To simplify programmers life, thinBasic File module has something similar as native functions:
    Last edited by ErosOlmi; 16-11-2023 at 07:35.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. canvas move control experiment
    By largo_winch in forum UI (User Interface)
    Replies: 3
    Last Post: 15-12-2011, 08:10
  2. New forum: move or wait?
    By ErosOlmi in forum Announcements
    Replies: 31
    Last Post: 06-11-2010, 21:42
  3. Simple TBGL Quad Rotate/Move example
    By Lionheart008 in forum TBGL module by Petr Schreiber
    Replies: 0
    Last Post: 19-02-2009, 17:13
  4. Move Lines
    By mrainey in forum thinAir General
    Replies: 5
    Last Post: 14-11-2005, 20:41

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •