Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Utility Program

How can I delete more than one file (DEL *.*)? by wgcs
Posted: 26 Sep 02 (Edited 1 Dec 03)

While DELETE FILE will only do one file at a time, it's relatively simple to cycle through all the files found that match a given filemask / skeleton.  I'm sure you could write this for yourself, but it's always easier to use existing code then think it through again!

This function returns 0 if it successfully deletes all files that match pcMask.  If any files can't be deleted, the number of files that couldn't be deleted is returned.

This function should never throw an error, even if some files are in use.

PROCEDURE Del( pcMask )
* Del( Skeleton )
LOCAL lcPath, lcFile, lnRes, lnDelRes
  lnRes = 0

  DECLARE INTEGER DeleteFile IN kernel32 ;
    STRING lpFileName

  lcPath = ADDBS(JUSTPATH(pcMask))
  lcFile = sys( 2000, pcMask )      && Locate first file with this mask.
  do while .Not. Empty( lcFile )
    delete FILE(lcPath+lcFile)
    lnDelRes = DeleteFile(pcFile)
    if lnDelRes=0
      lnRes = lnRes+1
    lcFile = sys( 2000, pcMask, 1 )  && find next matching file.

PROCEDURE SafeDel( pcFile )
* Delete a file without throwing an error.
DECLARE INTEGER DeleteFile IN kernel32 ;
  STRING lpFileName
res = DeleteFile(pcFile)
RETURN res<>0

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close