Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete File Errors
Message
 
 
À
26/04/2005 08:42:26
Steven Dyke
Safran Seats USA
Texas, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01008399
Message ID:
01008434
Vues:
14
>Since Delete File does not return any value what is the best way to trap for errors when Delete File fails?
*Forum: Visual FoxPro Category: Third party products Title: Re: Putting pictures in a zip file Thread #466323 Message #467098

*  SHFileOperation() Delete usage example: 
*  Windows doesn't require user intervention to confirm the deletions.
*  Progress dialog will appear in the current active window if it takes
*  long enough to fire the dialog; may be idle and unresponsive for a
*  while with no errors.  If you let the conformation dialog run, it
*  pops nearly instantly.
*
* Created by Ed Rauh

*  ClsHeap can be found in the Files section
*
lparameters cSourceString && String of files to delete
DECLARE INTEGER SHFileOperation IN SHELL32.DLL STRING @ LPSHFILEOPSTRUCT
DECLARE INTEGER GetActiveWindow IN WIN32API
SET PROCEDURE TO CLSHEAP ADDITIVE
LOCAL oHeap, cVBNull, llReturn, nStringBase, cFileOpStruct, llReturn
oHeap = CREATEOBJECT('Heap')
cVBNull = CHR(0)
#DEFINE FO_DELETE 3
#DEFINE FOF_NOCONFIRMATION 0x10    &&  Don't prompt the user.
#DEFINE FOF_FILESONLY 0x80         &&  Don't nail subfolders.
*  Explicitly declare a full path to avoid the vagaries of exactly what
*  Windows is using to resolve the path, each file spec ends with a
*  terminating null, with the last one double null terminated
if vartype(m.cSourceString)<>"C"
      cSourceString = 'C:\MyDir\*.BAK' + cVBNull + ;
                'C:\YourDir\YourFileName.TXT' + cVBNull + ;
                'C:\MyDir\MyTempDBF.*' + cVBNull + cVBNull
endif
nStringBase = oHeap.AllocBlob(cSourceString)
cFileOpStruct = NumToDWORD(GetActiveWindow()) + ;
                NumToDWORD(FO_DELETE) + ;
                NumToDWORD(nStringBase) + ;
                NumToDWORD(0) + ;
                NumToDWORD(FOF_NOCONFIRMATION) + ;
                cVBNull + ;
                NumToDWORD(0) + ;
                NumToDWORD(0)
llReturn = SHFileOperation(@cFileOpStruct) = 0
IF SUBST(cFileOpStruct,21,1) # cVBNull
   *  Some part of the operation was aborted or failed
   llReturn  = .f.
ENDIF

RETURN m.llReturn
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform