rm.c

final_realms_fluffos_v1/lib/cmds/creator.old/rm.c · 1.1 KB

From the archive final_realms_fluffos_v1.zip

Download the archive   « Back to the archive contents

#include <standard.h>
#include <cmd.h>
inherit CMD_BASE;

void setup(){

position = 1;
}



static int cmd(string str, object me) {
    int fsize, pos, loop;
    string *filenames;

  if (this_player(1) != this_player()) return 0;

    if (!str) {
       notify_fail("Usage: rm file [file ...]\n");
       return 0;
    }
    filenames = this_player()->get_files(str);
    if (!sizeof(filenames)) {
        notify_fail("No such file : " + str + "\n");
       return 0;
    }
    for(loop = 0; loop < sizeof(filenames); loop++) {
       string temp;
       str = filenames[loop];
       if(sscanf(str, "%s/.", temp) || sscanf(str, "%s/..", temp)) {
           continue;
       }
       fsize = file_size(str);
        if (fsize == -1) {
          notify_fail("No such file or directory.\n");
          return 0;
       }
       if (fsize == -2) {
          if (!rmdir(str)) {
             notify_fail("Couldn't rm directory: " + str + "\n");
             return 0;
          }
       } else if (!rm(str)) {
           notify_fail("Can't remove file.\n");
          return 0;
       }
    }
    write("Ok.\n");
    return 1;
} /* rm_files() */
 

Site Stats

Snippets: 1791
Codebases: 571