递归扫描SD卡Android NDK
Recursivly scan sd card android ndk
我在Android NDK中确实是新手,我感谢任何帮助。如何使用检查扩展名中的C 中扫描递归文件夹?我知道在Java很容易做。在Java中,我使用此:
public void scan(File root) {
File[] list = root.listFiles(tracksFilter);
for (File f : list) {
String path;
if (f.isDirectory()) {
scan(f);
} else if(path.endWith(".mp3"){
doMP3(f);
} else if(path.endWith(".png"){
doPNG(f);
}
}
}
值得记住的是,本机代码不会总是出于多种原因而导致绩效提高。在Java代码和等效的本机代码之间进行速度比较可能是有益的。结果可能会让您感到惊讶:)
也就是说,以下C 代码应该使您朝正确的方向前进。
...
#include <dirent.h>
#include <string>
#include <iostream>
....
static const string curDir = ".";
static const string parDir = "..";
....
void iterateDir(string path)
{
DIR *dir;
struct dirent *drnt;
dir = opendir(path.c_str());
while ((drnt = readdir(dir)) != NULL)
{
string name(drnt->d_name);
unsigned char = drnt->d_type;
if (name != curDir && name != parDir && name.length() >= 4)
{
if (type == DT_DIR) {
string newPath = path + name + "/";
iterateDir(newPath);
}
else if (name.find(".mp3") == (name.length() - 4)) {
doMP3(path + name);
}
else if (name.find(".png") == (name.length() - 4)) {
doPNG(path + name);
}
}
}
相关文章:
- Android NDK传感器向事件队列报告奇怪的间隔
- Android NDK 编译 LAME HAVE_MPGLIB > 'interface.h' 文件未找到
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- 在 constexpr 构造函数 (c++17) 中赋值到 const char * 在使用 Android NDK 时
- 如何在 android ndk 上链接 C 和 C++ 代码,以及 C 和 C++ 运行时库(包括 STL)?
- Android NDK 未定义对ASensorEventQueue_registerSensor的引用
- 如何将 libjpeg-turbo Android NDK 添加为静态库
- 在 Flutter 应用程序中使用 Android NDK 中的 AssetManager 类
- Android NDK - 无法在 Visual Studio 2017 中调试
- 不再支持Android NDK APP_STL gnustl_shared
- Android NDK:用于第三方Java库的静态或共享C++运行时
- 为 Android NDK 编译库
- 从文件问题加载纹理 Android NDK 和 OpenGL
- Android NDK - C++ 异常会导致第三方原生库崩溃
- 如何在 Android/NDK 上将命令行参数从 gradlew.bat 传递到 Clang
- [android ndk]如何获取资产文件夹中文件的绝对路径?
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 如何在Android(NDK)中使用CPR库
- 使用 Android NDK 使用 clang++ 编译C++代码时对"_Unwind_Resume"的未定义引用
- 如何在 C/Android NDK 中将字符串日期转换为毫秒