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

📄 fs_diroperations.c

📁 此为整套uC/FS程序
💻 C
字号:
/*
**********************************************************************
*                          Micrium, Inc.
*                      949 Crestview Circle
*                     Weston,  FL 33327-1848
*
*                            uC/FS
*
*             (c) Copyright 2001 - 2006, Micrium, Inc.
*                      All rights reserved.
*
***********************************************************************

----------------------------------------------------------------------
----------------------------------------------------------------------
File        : DirOperations.c
Purpose     : This sample creates 3 directories. In each directory
              32 files are created.
              After creating the directories and files, the contents
              of each directory is shown.
---------------------------END-OF-HEADER------------------------------
*/

#include <string.h>
#include <stdio.h>
#include "FS.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#ifndef COUNTOF
  #define COUNTOF(a) (sizeof(a) / sizeof(a[0]))
#endif

#define MAX_RECURSION         5

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
static char _acBuffer[0x1000];

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/


/*********************************************************************
*
*       _Init
*
*/
static void _Init(const char * sVolumeName) {
  FS_FormatLLIfRequired(sVolumeName);
  //
  // Check if volume needs to be high level formatted.
  //
  if (FS_IsHLFormatted(sVolumeName) == 0) {
    printf("High level formatting: %s\n", sVolumeName);
    FS_Format(sVolumeName, NULL);
  }
}

/*********************************************************************
*
*       _ShowDir
*
*/
static void _ShowDir(const char * sDirName, int MaxRecursion) {
  FS_FIND_DATA fd;
  char         acFileName[20];
  char         acDummy[20];
  unsigned     NumBytes;
  char         r;
  
  NumBytes = MAX_RECURSION - MaxRecursion;
  memset(acDummy, ' ', NumBytes);
  acDummy[NumBytes] = 0;
  sprintf(_acBuffer, "%sContents of %s \n", acDummy, sDirName);
  FS_X_Log(_acBuffer);
  if (MaxRecursion) {
    r = FS_FindFirstFile(&fd, sDirName, acFileName, sizeof(acFileName));
    if (r == 0) {
      do {
        U8 Attr;

        Attr = fd.Attributes;
        sprintf(_acBuffer,"%s %s %s Attributes: %s%s%s%s Size: %lu\n", acDummy, fd.sFileName,
                            (Attr & FS_ATTR_DIRECTORY) ? "(Dir)" : "     ",
                            (Attr & FS_ATTR_ARCHIVE)   ? "A" : "-",
                            (Attr & FS_ATTR_READ_ONLY) ? "R" : "-",
                            (Attr & FS_ATTR_HIDDEN)    ? "H" : "-",
                            (Attr & FS_ATTR_SYSTEM)    ? "S" : "-",
                            fd.FileSize);
        FS_X_Log(_acBuffer);
        if (Attr & FS_ATTR_DIRECTORY) {
          char acDirName[256];
          //
          // Show contents of each directory in the root
          //
          if (*fd.sFileName != '.') {
            sprintf(acDirName, "%s\\%s", sDirName, fd.sFileName);
            _ShowDir(acDirName, MaxRecursion - 1);
          }
        }

      } while (FS_FindNextFile(&fd));
      FS_FindClose(&fd);
    } else if (r == 1) {
      FS_X_Log("Directory is empty");
    } else {
      char acErr[80];
   
      sprintf(acErr, "Unable to open directory %s\n", sDirName);
      FS_X_ErrorOut(acErr);
    }
    FS_X_Log("\n");
  }
 
}


/*********************************************************************
*
*       Public code
*
**********************************************************************
*/

/*********************************************************************
*
*       MainTask  
*/
void MainTask(void);      // Forward declaration to avoid "no prototype" warning
void MainTask(void) {
  char         acVolName[20];
  int          NumVolumes;
  int          i;
  
  FS_Init();
  NumVolumes = FS_GetNumVolumes();
  for (i = 0; i < NumVolumes; i++) {
    FS_GetVolumeName(i, acVolName, sizeof(acVolName));
    _Init(acVolName);
    //
    // Show contents of root directory
    //
    _ShowDir(acVolName, MAX_RECURSION);
  }
  while(1);
}


/*************************** End of file ****************************/

⌨️ 快捷键说明

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