Programmatically Using DELETE FILE with a File Skeleton

Last reviewed: June 27, 1995
Article ID: Q109985
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b

SUMMARY

The FoxPro DELETE FILE function does not accept wildcards. To delete files using wildcards, you must build a program that loops through all files meeting the file specification and pass the filenames one by one to the DELETE FILE function.

The program below is provided as an example of using FoxPro's functions to simulate the MS-DOS DELETE command.

MORE INFORMATION

   * Procedure to delete a number of files using a file skeleton
   * similar to the MS-DOS command DEL *.BAK. Just like its MS-DOS
   * equivalent, you can also pass it a path if the files to be
   * deleted are NOT in the default (current) directory. Use with
   * caution!
   *
   PARAMETERS whatpath
   IF TYPE("whatpath")#"C"
      WAIT WINDOW 'You must pass a file skeleton'+CHR(13)+ ;
                  'Such as "*.*" or "C:\FOXPROW\DATA\*.BAK"'
      RETURN
   ENDIF

   SET TALK OFF
   SET SAFETY OFF
   libactive=.F.
   CLEAR

   filecount=0
   filename=SYS(2000,whatpath)        && return first filename
   DO WHILE LEN(filename) > 0         && is there a file?
      IF filecount=0                  && do this only the first time
         *activate library
         SET LIBRARY TO SYS(2004)+'foxtools' ADDITIVE
         libactive=.T.                && boolean to indicate library use
      ENDIF
      DELETE FILE (forcepath(filename, justpath(whatpath)))  && lib call
      filecount=filecount+1           && keep track of number of files
      filename=SYS(2000,whatpath,1)   && next filename
   ENDDO
   IF libactive                       && if library was opened, close it
      RELEASE LIBRARY SYS(2004)+'foxtools'
   ENDIF
   ? ALLTRIM(STR(filecount)) + ' Files deleted.'


Additional reference words: FoxWin 2.00 2.50 2.50a 2.50b DELETE FILE *.*
SYS(2000)
SYS(2004)
KBCategory: kbprg kbcode
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.