Programmatically Using DELETE FILE with a File Skeleton

ID: Q109985

The information in this article applies to:

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

Last Reviewed: June 27, 1995