wiki:Docs/Prog/Manual/ApplicationLibraries/lib825ev/File/FindFlashDrive

Version 1 (modified by Don Wilson, 6 months ago) ( diff )

--

FindFlashDrive

Search for plugged in flash drives

bool FindFlashDrive(std::vector<string>& pathList, bool checkForUnmounted = false);

Parameters

pathList = a vector of std::string to be populated with the result paths found checkForUnmounted = If true will also check if drive is unmounted and mount it

Return Value

This function returns true if any flash drive found/mounted.

Remarks

The function reads /proc/mounts to obtain the result.

Examples

  int result;
  char writeFilePath[180];
#if ARM64
  vector<string> pathList;
  if(FindFlashDrive(pathList, true) == false) {
    result = -1;
  } else {
    result = 0;
    // pathList item will already have a trailing slash
    // so writeFilePath will become something like "/run/media/sda1/data.csv"
    sprintf_s(writeFilePath, "%sdata.csv", pathList[0].c_str());
  }
#else
  result = system("mount -t vfat /dev/sda1 /mnt/fl1");
  strcpy(writeFilePath, "/mnt/fl1/data.csv");
#endif
  if(result != 0) {
     DrawErrorBox("Error mounting USB drive", 2);
  } else {
      // ... Write data to flash drive

#if ARM64
    UnmountDirectory(pathList[0].c_str());
#else
    system("umount /mnt/fl1");
#endif
  }



See Also

Note: See TracWiki for help on using the wiki.