INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!

*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.

Jobs

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
    endif
    lcFile = sys( 2000, pcMask, 1 )  && find next matching file.
  enddo
RETURN lnRes
ENDPROC

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


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

My Archive

Resources

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