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

📄 fiufind.cpp

📁 用c++变得一个测量财富的+游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************* Procedure Body *****************************/

// Save the full path and return it with file name(s)
// found.

filFile = NULL;

filStat = FIUextractPath( pasFileSpec, FIP_MAX_NAME_LEN, fimFindPath );

if (filStat == SUCCEEDED_)
  {
  filErr = fiuFindFirst( pasFileSpec, &fimFblk  );
  if (filErr == SUCCEEDED_)
    {
    if (pasReturnFullPath)
      {
      FIUconstructFilePath( fimFindPath,
                            fimFblk.name,
                            FIP_MAX_NAME_LEN,
                            fimFindFile );
      }
    else
      {
      strcpy(fimFindFile, fimFblk.name );
      }
    filFile = (const char *)fimFindFile;
    }
  }

return( filFile );
} /* FIUgetFirstFilename end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUgetNextFilename

    PURPOSE:  to get the next file name based on the results
      a previous call to FIUgetFirstFilename.
      Return a character pointer to the filename.  If no file found
      return NULL.

**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filErr             STAT_TYPE, SUCCEEDED_ or FAILED_              **
**\p*******************************************************************/

const char *FIUgetNextFilename( BOOLEAN     pasReturnFullPath)
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE        filErr;
const char      *filFile;
/************************* Procedure Body *****************************/
filFile    =  NULL;
filErr     =  fiuFindNext( &fimFblk );
if (filErr == SUCCEEDED_)
  {
  if (pasReturnFullPath)
    {
    FIUconstructFilePath( fimFindPath,
                          fimFblk.name,
                          FIP_MAX_NAME_LEN,
                          fimFindFile );
    }
  else
    {
    strcpy( fimFindFile, fimFblk.name );
    }
  filFile = (const char *)fimFindFile;
  }
return(filFile);
} /* FIUgetNextFilename end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUextractPath

    PURPOSE:  to extract full path from full path/file specification.
      The outputted path will include the drive specifier, if any
      is given, as well.


**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filErr             STAT_TYPE, SUCCEEDED_ or FAILED_              **
**\p*******************************************************************/

STAT_TYPE FIUextractPath( const char *pasFilePath,
                          int         pasDestLen,
                          char       *refFullPath )
{
/*********** Local Constant & Variable Declarations *******************/
//CHAR                   *FIL_PROC_NAME = "FIUextractPath";
STAT_TYPE               filErr        = SUCCEEDED_; /* Iniz ret val   */
char                   *filDs;
/************************* Procedure Body *****************************/

if ((pasFilePath == NULL) ||
    (pasDestLen <= 0)     ||
    (refFullPath == NULL))
  {
  filErr = FAILED_;
  }
else
  {
  LIUstrncpy( refFullPath, (char *)pasFilePath, pasDestLen );
  filDs = LIUstrchrLast( refFullPath, FIP_PATH_SEP );
  if (filDs)
    {
    filDs++;
    *filDs = '\0';
    }
  else
    {
    filDs = strchr( refFullPath, FIP_DRIVE_SEP );
    if (filDs)
      {
      filDs++;
      *filDs = '\0';
      }
    else
      {
      *refFullPath = '\0';
      }
    }
  }
return(filErr);
} /* FIUextractPath end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  FIUconstructFilePath

    PURPOSE:  to combine the filename and path name into a
      complete path\file specification.  If trailing '\'
      is missing from path, add it before appending file
      name.  Keep careful watch on length of destination string
      so that we don't overrun its length.  If destination
      string is too short, return FAILED_, else return
      SUCCEEDED_.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   filErr             FNC    (SUCCEEDED_ / FAILED_) error return    **
**\p*******************************************************************/

STAT_TYPE FIUconstructFilePath
( const char    *pasPath,
  const char    *pasFileName,
  int            pasNameLen,
  char          *refFilePath )

{ /* FIUconstructFilePath procedure */

/******************* Local Constant Declarations **********************/
/* Proc name for error log */
#define FIL_MIN_LEN 3

/******************* Local Variable Declarations **********************/
/* error return flag       */
STAT_TYPE               filErr;
int                     filLen;
int                     filCatLen;

/************************* Procedure Body *****************************/

filErr = FAILED_;

if (pasNameLen > FIL_MIN_LEN || refFilePath != NULL)
  {
  LIUstrncpy( refFilePath, (char *)pasPath, pasNameLen-1 );
  filLen = strlen(refFilePath);
  if ( (filLen > 0) &&
       (refFilePath[filLen-1] != FIP_PATH_SEP) &&
       (refFilePath[filLen-1] != FIP_DRIVE_SEP) )
    {
    refFilePath[filLen]   = FIP_PATH_SEP;
    refFilePath[filLen+1] = '\0';
    filLen++;
    }
  filCatLen = pasNameLen - filLen;
  if (filCatLen > 0)
    {
    strncat(refFilePath, pasFileName, filCatLen );
    refFilePath[pasNameLen-1] = '\0';
    filErr = SUCCEEDED_;
    }
  }
return(filErr);
} /* FIUconstructFilePath end */

/*\p********************************************************************
**                                                                    **
    NAME:  BOOLEAN FIUpathExists

    PURPOSE:  to see if the specified path exists

**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filFnd             BOOLEAN, true if found                        **
**\p*******************************************************************/

BOOLEAN FIUpathExists( const char *pasPath )
{
/*********** Local Constant & Variable Declarations *******************/
BOOLEAN filFnd;
STAT_TYPE filErr;

/************************* Procedure Body *****************************/

filErr = fiuFindFirst( pasPath, &fimFblk, FIG_SUBDIR );

if (filErr == SUCCEEDED_) filFnd = TRUE_;
else                      filFnd = FALSE_;

return(filFnd);
} /* FIUpathExists end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUgetDiskName

    PURPOSE:  to read the disk label name for the specified drive.

** By Matthew J. W. Ratcliff                                          **
**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filErr             STAT_TYPE, SUCCEEDED_ or FAILED_              **
**\p*******************************************************************/

STAT_TYPE FIUgetDiskName( int         pasDriveLetter,
                          int         pasStrLen,
                          char       *refDiskName )
{
/*********** Local Constant & Variable Declarations *******************/
#define FIL_MIN_LABEL_LEN       11 // Minimum disk label name length

STAT_TYPE               filErr;
char                    filDrv[10];
/************************* Procedure Body *****************************/

if ((!refDiskName) || (pasStrLen < FIL_MIN_LABEL_LEN))
  {
  filErr = FAILED_;
  }
else
  {
  strcpy(filDrv,"X:\\*.*");
  // If caller passed drive NUMBER convert to letter
  if (pasDriveLetter < 'A')
    {
    pasDriveLetter += (int)'A';
    }
  filDrv[0] = (char)pasDriveLetter;
  filErr    = fiuFindFirst( filDrv, &fimFblk, FIG_VOLID );
  if (filErr == SUCCEEDED_)
    {
    LIUstrncpy( refDiskName, fimFblk.name, pasStrLen );
    }
  else
    {
    *refDiskName = '\0';
    }
  }

return(filErr);
} /* FIUgetDiskName end */

⌨️ 快捷键说明

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