⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm.c

📁 picoos源码。The RTOS and the TCP/IP stack will be built automatically.
💻 C
字号:

/* Simple rm clone for DOS/WIN32
 *
 * Note: 
 *  1) This rm does not support removing of directory trees.
 *  2) Use the MinGW GCC compiler to compile this file.
 *
 * This file is part of pico]OS. License: modified BSD
 */


#include <io.h>
#include <stdio.h>
#include <string.h>

#define MAXPATHLEN   500


int main(int argc, char *argv[])
{
  struct _finddata_t fn;
  char c, buf[MAXPATHLEN];
  int d, b, p, i, h;

  /* walk over all parameters */  
  d = 0;
  for (p = 1; p < argc; p++)
  {
    /* skip all flag parameters */
    if (argv[p][0] == '-')
      continue;

    /* Copy string, replace slash by backslash. 
       Remember position of last slash. */
    for (b = 0, i = 0; (i < MAXPATHLEN-1) && (argv[p][i] != 0); i++)
    {
      c = argv[p][i];
      if ((c == '/') || (c == '\\'))
      {
        buf[i] = '\\';
        b = i + 1;
      }
      else
      {
        buf[i] = c;
      }
    }
    buf[i] = 0;
    if (b == i)
    {
      strcpy(buf+b, "*.*");
    }

    /* find all files */
    d = 1;
    h = _findfirst(buf, &fn);
    i = h;
    while (i != -1)
    {
      /* copy filename to buffer */
      strcpy(buf+b, fn.name);

      if ((fn.attrib & _A_SUBDIR) == 0)
      {
        /* delete file */
        remove(buf);
      }
      else
      {
        /* delete (empty) directory */
        rmdir(buf);
      }

      i = _findnext(h, &fn);
    }
    _findclose(h);

  }

  if (d == 0)
  {
    printf("\nUnix rm clone for the DOS/WIN32 environment\n");
  }

  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -