[수정]이 함수 좀 봐주세요
글쓴이: lalupo20 / 작성시간: 토, 2018/10/20 - 7:40오후
const char* Utils::searchSDCardPath(const char* path) {
DIR* dp;
struct dirent* entry;
static bool find = false;
static string aPath;
dp = opendir(path);
if (dp == NULL) {
return NULL;
}
LOGI(path);
while ((entry = readdir(dp))) {
if (strcmp(entry->d_name, ".") == 0 ||
strcmp(entry->d_name, "..") == 0) {
continue;
}
if (entry->d_type == DT_DIR) {
LOGI("folder name %s", entry->d_name);
string pathStr = path;
if (strcmp(entry->d_name, "Download") == 0) {
find = true;
aPath = path;
LOGI("path - %s", aPath.c_str());
return aPath.c_str();
}
else {
pathStr += "/";
pathStr += string(entry->d_name);
chdir(pathStr.c_str());
searchSDCardPath(pathStr.c_str());
chdir("..");
}
if (find == true)
return aPath.c_str();
}
}
closedir(dp);
return path;
}android sdcard 절대경로를 찾기 위한 코드입니다.
모든 기기 동일하게 sdcard 경로 안에 Download라는 폴더가 있다는 사실을 근거로 작성한 코드 입니다.
원래는 Android 폴더가 있다는 가정으로 찾았었는데
내부에 Android라는 폴더가 또 있을지도 모른다는 생각이 들어서 Download로 바꾸었습니다.
이 코드 제 핸드폰에서는 정상작동하는데 갤s7에서는 정상작동하지 않네요.
어떤 문제가 있을 수 있나요?
절대경로 추출하는거 이 방법 말고 다른 방법은 없을까요?
경험해보신분이 계신다면 조언 부탁드립니다.
Forums:


댓글 달기