Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error handling
Message
From
10/03/2000 14:59:52
 
 
To
29/02/2000 04:42:31
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Miscellaneous
Thread ID:
00338981
Message ID:
00344377
Views:
17
You can write a Custom class to implement the function. For example, I wrapped the DELETE FILE native command with a DeleteFile() function that is in turn implemented by the clDeleteFile custom class.

Hope this help.

Daniel

****************************************************************************
** DeleteFile
** ----------
**
** Purpose : Delete a file from a disk.
** Author : Daniel Rouleau - Metro Information Services (97/11/07)
** Revision : 1.0
**
** Syntax : DeleteFile(tcFileName, [tlRecycle])
** Returns : logical
** Arguments : tcFileName - Specifies the file to delete. tcFileName
** can contain wildcards such as * and ?.
** tlRecycle - Specifies if the files go in the Recycle bin.
**
** Calls : n/a
** Called By : no restriction
**
** Remarks : DeleteFile returns TRUE if the files no longer exists
** after deletion and FALSE otherwise. Note that it returns
** TRUE if the files don't exist in the first place.
**
** DeleteFile is basically a wrapper for the DELETE FILE
** command.
**
** Note that DELETE FILE ... RECYCLE always succeed, even if
** the file is currently in use (I don't know whether this
** is a VFP bug or one of those undocumented "features").
** This explains why I always check for existence after
** deletion despite the error handler setting the flag
** correctly in non-recycled cases.
*****************************************************************************
LPARAMETERS tcFileName, tlRecycle

LOCAL llRetVal && Value returned by this function.
LOCAL laFiles[1, 5] && Files matching the lcFileName skeleton.
LOCAL lcFileName && File to delete.
LOCAL loObject && Reference to the DeleteFile object.
LOCAL llRecycle && True if the deleted files go into the Recycle bin.

llRetVal = .T.
lcFileName = IIF(TYPE("tcFileName") == "C", ALLTRIM(m.tcFileName), "")
llRecycle = IIF(TYPE("tlRecycle") == "L", m.tlRecycle, "")

IF (ADIR(laFiles, m.lcFileName) > 0) && At least one file to delete.
* -- Create the DeleteFile object.
loObject = CREATEOBJECT("clDeleteFile")

* -- Delete File
IF (TYPE("loObject") == "O") AND NOT ISNULL(loObject)
loObject.FileName = m.lcFileName
loObject.Recycle = m.llRecycle
llRetVal = loObject.DeleteFile()
loObject = .NULL.
ELSE
llRetVal = .F.
ENDIF

RELEASE loObject
ENDIF


RETURN ( m.llRetVal )

********************************
** **
** clDeleteFile Class **
** **
********************************

DEFINE CLASS clDeleteFile AS custom
FileName = ""
Recycle = .F.

PROCEDURE DeleteFile
LOCAL lcFileName
LOCAL laFiles[1, 5]
LOCAL llRecycle
LOCAL llRetVal

lcFileName = THIS.FileNAme
llRecycle = THIS.Recycle

IF m.llRecycle
DELETE FILE (m.lcFileName) RECYCLE
ELSE
DELETE FILE (m.lcFileName)
ENDIF

llRetVal = (ADIR(laFiles, m.lcFileName) = 0)


RETURN ( m.llRetVal )
ENDPROC

PROCEDURE Error
LPARAMETERS tnError, tcMethod, tnLine

LOCAL lcErrText
LOCAL lcFileName

lcErrText = ""
lcFileName = UPPER(ALLTRIM(THIS.FileName))

DO CASE
CASE m.tnError = 1
* -- File does not exist.
* -- Ignore this error
lcErrText = ""

CASE m.tnError = 3
* -- File is in use.
lcErrText = "The '" + m.lcFileName + "'file is " + ;
"in use and cannot be deleted." + ;
KEY_ENTER + KEY_ENTER + ;
"Close all Microsoft Word documents and try " + ;
"again. Contact your technical support team " + ;
"if the error persists."

CASE m.tnError = 108
* -- File is in use by another user.
lcErrText = "The '" + m.lcFileName + "'file is " + ;
"in use by another user and cannot be deleted."

OTHERWISE
lcErrText = "An unexpected error " + LTRIM(STR(m.tnError)) + ;
"occurred while deleting the '" + m.lcFileNAme + ;
"'." + ;
KEY_ENTER + KEY_ENTER + ;
"Please report this error to your technical " + ;
"support team."
ENDCASE


IF NOT EMPTY(m.lcErrText)
=RingBell()
=MessageBox(m.lcErrText, MB_OK + MB_ICONSTOP, "Delete File Error")
ENDIF
ENDPROC
ENDDEFINE
Previous
Reply
Map
View

Click here to load this message in the networking platform