Jason Edmeades : cmd.exe: Support del /f.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Feb 28 08:19:14 CST 2007


Module: wine
Branch: master
Commit: 10c3764d13ab5a58a08ae741fc289293697885c3
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=10c3764d13ab5a58a08ae741fc289293697885c3

Author: Jason Edmeades <us at edmeades.me.uk>
Date:   Tue Feb 27 23:20:25 2007 +0000

cmd.exe: Support del /f.

---

 programs/cmd/builtins.c |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index c7c4839..6b214e1 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -271,14 +271,17 @@ char *p;
     WCMD_output ("%s :File Not Found\n",param1);
     return;
   }
+  /* Support del <dirname> by just deleting all files dirname\* */
   if ((strchr(param1,'*') == NULL) && (strchr(param1,'?') == NULL)
   	&& (!recurse) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
     strcat (param1, "\\*");
     FindClose(hff);
     WCMD_delete (1);
     return;
-  }
-  if ((strchr(param1,'*') != NULL) || (strchr(param1,'?') != NULL)) {
+
+  } else {
+
+    /* Build the filename to delete as <supplied directory>\<findfirst filename> */
     strcpy (fpath, param1);
     do {
       p = strrchr (fpath, '\\');
@@ -288,28 +291,34 @@ char *p;
       }
       else strcpy (fpath, fd.cFileName);
       if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
+        BOOL  ok = TRUE;
+
         /* /P means prompt for each file */
         if (strstr (quals, "/P") != NULL) {
-          BOOL  ok;
           char  question[MAXSTRING];
 
           /* Ask for confirmation */
           sprintf(question, "%s, Delete", fpath);
           ok = WCMD_ask_confirm(question, FALSE);
+        }
 
-          /* Only delete if answer is 'Y' */
-          if (ok && !DeleteFile (fpath)) WCMD_print_error ();
-        } else {
+        /* Only proceed if ok to */
+        if (ok) {
+
+          /* If file is read only, and /F supplied, delete it */
+          if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY &&
+              strstr (quals, "/F") != NULL) {
+              SetFileAttributes(fpath, fd.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
+          }
+
+          /* Now do the delete */
           if (!DeleteFile (fpath)) WCMD_print_error ();
         }
+
       }
     } while (FindNextFile(hff, &fd) != 0);
     FindClose (hff);
   }
-  else {
-    if (!DeleteFile (param1)) WCMD_print_error ();
-    FindClose (hff);
-  }
 }
 
 /****************************************************************************




More information about the wine-cvs mailing list