Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to delete a temporary cursor created with READWRITE
Message
From
13/05/2008 20:08:29
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01316829
Message ID:
01316859
Views:
14
>>In one of my forms I use SELECT statements to create cursors READWRITE because I want to modify them sometime later.
>>
>>After the form closes, I notice that these cursors have not been deleted.
>>
>>What is the best way to delete temporary cursors that have been created with READWRITE attribute? It seems that they don't automatically get deleted when the form closes.
>>
>>Thanks,
>>Jim
>
>Hmmmm.... USE IN cCursorName
>
>OK
>
>I guess it is just getting to be a long day.
>
>Jim

Just FYI, but if VFP crashes, the .tmp files will not be erased. They will not be in use. So a piece of code that iterates through .tmp files can be used to delete those that are not currently in use.
LPARAMETERS m.tcFolderName,m.tcDeleteFileSkeletons
*
*  DELETEFILES.PRG
*
*  Deletes all files according to the specified delete
*  file skeletons in the specified folder. Intended
*  specifically to delete VFP temporary files.
*
*  RETURNs the number of files successfully deleted.
*
*  Author:  Mike Yearwood
*
*  Usage:
*
*    At startup and/or shutdown of a VFP EXE/APP
*    either of
*      DO DELETEFILES WITH "*.tmp,*.cdx"
*    or
*      LOCAL m.lnFiles
*      m.lnFiles = DELETEFILES("*.tmp,*.cdx")
*
*  lParameters
*    tcFolderName (R) Folder containing files to delete.
*
*    tcDeleteFileSkeletons (R) comma-delimited list of File Skeletons 
*    such as "*.tmp,*.cdx,*.txt" or simply "*.tmp"
*                  

ASSERT ;
    VARTYPE(m.tcFolderName) = "C" ;
        AND NOT EMPTY(m.tcFolderName) ;
    MESSAGE "FolderName must be character and not empty."

ASSERT ;
    VARTYPE(m.tcDeleteFileSkeletons) = "C" ;
        AND NOT EMPTY(m.tcDeleteFileSkeletons) ;
    MESSAGE "DeleteFileSkeleton must be character and not empty."
    
m.tcFolderName = ADDBS(m.tcFolderName)
#DEFINE kcDelimiter ","
LOCAL ;
    m.lnFilesDeleted, ;
    m.lnIteration, ;
    m.lcDeleteFileSkeleton, ;
    m.lcFileName

m.lnFilesDeleted = 0

FOR m.lnIteration = 1 TO GETWORDCOUNT(m.tcDeleteFileSkeletons,kcDelimiter)
    m.lcDeleteFileSkeleton = GETWORDNUM(m.tcDeleteFileSkeletons,m.lnIteration,kcDelimiter)
    m.lcFileName = SYS(2000,m.tcFolderName + m.lcDeleteFileSkeleton)
    DO WHILE NOT EMPTY(m.lcFileName)
        TRY
            ERASE (m.tcFolderName + m.lcFileName)
            m.lnFilesDeleted = m.lnFilesDeleted + 1
        CATCH TO m.loError
            *File could not be deleted - probably is in use, so do nothing.
        ENDTRY
        m.lcFileName = SYS(2000,m.tcFolderName + m.lcDeleteFileSkeleton,1)
    ENDDO
ENDFOR m.lnIteration
RETURN m.lnFilesDeleted
Previous
Reply
Map
View

Click here to load this message in the networking platform