int CGb2Utf8::TransformPath(CString *path_from, CString *path_to) { ACL_SCAN_DIR *scan_src; //, *scan_dst; const char *path = path_from->GetString(); scan_src = acl_scan_dir_open(path, 1); if (scan_src == NULL) { CString msg; msg.Format("Open src path %s error", path_from->GetString()); MessageBox(NULL, msg, "Open path", 0); return (-1); } //scan_dst = acl_scan_dir_open(to.GetString(), 1); //if (scan_dst == NULL) { // MessageBox(NULL, "Open path", "Open dst path error", 0); // return (-1); //} while (1) { const char *fName; CString fPath; fName = acl_scan_dir_next_file(scan_src); if (fName == NULL) break; fPath = acl_scan_dir_path(scan_src); fPath += "\\"; fPath += fName; TransformFile(fPath.GetString(), NULL); } acl_scan_dir_close(scan_src); return (0); }
acl_int64 acl_scan_dir_size(const char *pathname, int recursive, int *nfile, int *ndir) { const char *myname = "acl_scan_dir_size"; ACL_SCAN_DIR *scan; acl_int64 size; if (pathname == NULL || *pathname == 0) { acl_msg_error("%s(%d), %s: pathname null", __FILE__, __LINE__, myname); return -1; } scan = acl_scan_dir_open(pathname, recursive); if (scan == NULL) { acl_msg_error("%s(%d), %s: dir_open error: %s, path: %s", __FILE__, __LINE__, myname, acl_last_serror(), pathname); return -1; } size = acl_scan_dir_size2(scan, nfile, ndir); acl_scan_dir_close(scan); return size; }
void* CDelBOM::RunThread(void *arg) { CDelBOM* pDel = (CDelBOM*) arg; ACL_SCAN_DIR *scan = acl_scan_dir_open(pDel->m_sPath.GetString(), 1); if (scan == NULL) { CString msg; msg.Format("Open path %s error", pDel->m_sPath.GetString()); MessageBox(NULL, msg, "Open path", 0); ::PostMessage(pDel->m_hWnd, pDel->m_nMsgDeleted, 0, 0); return NULL; } while (true) { const char* pFile = acl_scan_dir_next_file(scan); if (pFile == NULL) break; // 过滤掉非纯文本的文件 if (acl_strrncasecmp(pFile, ".c", 2) && acl_strrncasecmp(pFile, ".cpp", 4) && acl_strrncasecmp(pFile, ".cxx", 4) && acl_strrncasecmp(pFile, ".h", 2) && acl_strrncasecmp(pFile, ".hpp", 4) && acl_strrncasecmp(pFile, ".hxx", 4) && acl_strrncasecmp(pFile, ".java", 5) && acl_strrncasecmp(pFile, ".txt", 4) && acl_strrncasecmp(pFile, ".php", 4) && acl_strrncasecmp(pFile, ".html", 5) && acl_strrncasecmp(pFile, ".js", 3) && acl_strrncasecmp(pFile, ".css", 4) && acl_strrncasecmp(pFile, ".d", 2) && acl_strrncasecmp(pFile, ".py", 3) && acl_strrncasecmp(pFile, ".perl", 5) && acl_strrncasecmp(pFile, ".cs", 3) && acl_strrncasecmp(pFile, ".as", 3)) { acl_msg_info(">>skip file: %s", pFile); continue; } CString filePath = acl_scan_dir_path(scan); filePath += "\\"; filePath += pFile; if (pDel->DeleteBOM(filePath) == true) acl_msg_info(">>modify file %s", filePath.GetString()); else acl_msg_info(">>skip file %s", filePath.GetString()); } acl_scan_dir_close(scan); ::PostMessage(pDel->m_hWnd, pDel->m_nMsgDeleted, 0, 0); acl_msg_info(">>scan over, msg: %d", pDel->m_nMsgDeleted); return NULL; }
bool queue_manager::scan_open(bool scanSub /* = true */) { string path = m_home.c_str(); path << PATH_SEP << m_queueName.c_str(); m_scanDir = acl_scan_dir_open(path.c_str(), scanSub ? 1 : 0); if (m_scanDir == NULL) { logger_error("open %s error(%s)", path.c_str(), acl_last_serror()); return false; } else return true; }
static int zdb_dat_scan_path(ZDB *db, const char *path, int (*walk_fn)(ZDB_DAT_STORE *store)) { const char *myname = "zdb_dat_scan_path"; ZDB_DAT_STORE *store; ACL_SCAN_DIR *scan; const char *fname; char pathbuf[256]; int ret = 0; scan = acl_scan_dir_open(path, 1); if (scan == NULL) { acl_msg_error("%s(%d): open dir %s error(%s)", myname, __LINE__, path, acl_last_serror()); return (-1); } while (1) { fname = acl_scan_dir_next_file(scan); if (fname == NULL) { acl_msg_info("%s(%d): scan over for %s", myname, __LINE__, path); break; } if (strrncasecmp(fname, ".dat", 4) != 0) { acl_msg_info("%s(%d): skip %s/%s", myname, __LINE__, acl_scan_dir_path(scan), fname); continue; } snprintf(pathbuf, sizeof(pathbuf), "%s/%s", acl_scan_dir_path(scan), fname); store = zdb_dat_store_open(db, pathbuf); if (store == NULL) { acl_msg_error("%s(%d): open file(%s) error(%s)", myname, __LINE__, pathbuf, acl_last_serror()); break; } ret = walk_fn(store); zdb_dat_store_close(store); if (ret < 0) { acl_msg_error("%s(%d): walk_fn ret: %d, break", myname, __LINE__, ret); break; } } acl_scan_dir_close(scan); return (ret); }
int zdb_key_walk(ZDB *db, int (*walk_fn)(ZDB_KEY_STORE*)) { const char *myname = "zdb_key_walk"; ZDB_KEY_STORE *store; ACL_SCAN_DIR *scan = NULL; const char *fname; char pathbuf[256]; int ret = 0; scan = acl_scan_dir_open(db->key_path, 1); if (scan == NULL) { acl_msg_error("%s: open dir %s error(%s)", myname, db->key_path, acl_last_serror()); return (-1); } while (1) { fname = acl_scan_dir_next_file(scan); if (fname == NULL) { acl_msg_info("%s: scan over for %s\n", myname, db->key_path); break; } if (strrncasecmp(fname, ".key", 4) != 0) { acl_msg_info("%s: skip %s/%s\n", myname, acl_scan_dir_path(scan), fname); continue; } snprintf(pathbuf, sizeof(pathbuf), "%s/%s", acl_scan_dir_path(scan), fname); store = zdb_key_store_open2(db, pathbuf); if (store == NULL) { acl_msg_error("%s: open file(%s) error(%s)", myname, pathbuf, acl_last_serror()); ret = -1; break; } ret = walk_fn(store); zdb_key_store_close(store); if (ret < 0) break; } acl_scan_dir_close(scan); return (ret); }
acl_int64 acl_scan_dir_rm(const char *pathname, int recursive, int *ndir, int *nfile) { const char *myname = "acl_scan_dir_rmall"; ACL_SCAN_DIR *scan; struct acl_stat sbuf; acl_int64 nsize; char tbuf[256]; if (ndir) *ndir = 0; if (nfile) *nfile = 0; if (acl_stat(pathname, &sbuf) < 0) { acl_msg_error("%s(%d), %s: stat pathname(%s) error(%s)", __FILE__, __LINE__, myname, pathname, acl_last_strerror(tbuf, sizeof(tbuf))); return (-1); } if (S_ISDIR(sbuf.st_mode) == 0) { if (nfile) *nfile = 1; SANE_UNLINK(pathname); return (1); } scan = acl_scan_dir_open(pathname, recursive); if (scan == NULL) { acl_msg_error("%s(%d), %s: open path(%s) error(%s)", __FILE__, __LINE__, myname, pathname, acl_last_strerror(tbuf, sizeof(tbuf))); return (-1); } acl_scan_dir_rm2(scan); if (ndir) *ndir = scan->ndirs; if (nfile) *nfile = scan->nfiles; nsize = scan->nsize; acl_scan_dir_close(scan); return (nsize); }
acl_int64 acl_scan_dir_size(const char *pathname, int recursive, int *nfile, int *ndir) { ACL_SCAN_DIR *scan; acl_int64 size; if (pathname == NULL || *pathname == 0) return (-1); scan = acl_scan_dir_open(pathname, recursive); if (scan == NULL) return (-1); size = acl_scan_dir_size2(scan); if (nfile) *nfile = scan->nfiles; if (ndir) *ndir = scan->ndirs; acl_scan_dir_close(scan); return (size); }
bool scan_dir::open(const char* path, bool recursive /* = true */) { if (path == NULL || *path == 0) { logger_error("path null"); return false; } // 先关闭之前可能打开的句柄,以防止资源泄漏 close(); path_ = acl_mystrdup(path); scan_ = acl_scan_dir_open(path_, recursive ? 1 : 0); if (scan_ == NULL) { logger_error("open dir: %s error: %s", path_, last_serror()); acl_myfree(path_); return false; } return true; }
static void scan_dir(const char *src_path, int to_fmt) { ACL_SCAN_DIR *scan; const char *filename, *path, *ptr; char filepath[1024], fmt_buf[32], info[32]; int n; #define CP ACL_SAFE_STRNCPY switch (to_fmt) { case FMT_UNIX: CP(info, "UNIX", sizeof(info)); CP(fmt_buf, "\n", sizeof(fmt_buf)); break; case FMT_DOS: CP(info, "DOS", sizeof(info)); CP(fmt_buf, "\r\n", sizeof(fmt_buf)); break; case FMT_MAC: CP(info, "MAC", sizeof(info)); CP(fmt_buf, "\r", sizeof(fmt_buf)); break; default: acl_msg_fatal("unknown fmt(%d)", to_fmt); } scan = acl_scan_dir_open(src_path, 1); if (scan == NULL) acl_msg_fatal("open path(%s, %s)", src_path, strerror(errno)); n = 0; while (1) { filename = acl_scan_dir_next_file(scan); if (filename == NULL) break; if (strlen(filename) < 3) continue; ptr = strchr(filename, '.'); if (ptr == NULL) continue; ptr++; if (strcasecmp(ptr, "c") != 0 && strcasecmp(ptr, "h") != 0 && strcasecmp(ptr, "cpp") != 0 && strcasecmp(ptr, "hpp") != 0) continue; path = acl_scan_dir_path(scan); if (path == NULL) acl_msg_fatal("file(%s) no path", filename); snprintf(filepath, sizeof(filepath), "%s/%s", path, filename); printf("filepath:%s\r\n", filepath); fmt_change(filepath, fmt_buf); n++; } acl_scan_dir_close(scan); printf(">>> At last, %d files were changed to %s format\r\n" ">>> total_c_line: %d lines, total_h_line: %d, " "total_cpp_line: %d, total_hpp_line: %d\r\n", n, info, __total_c_line, __total_h_line, __total_cpp_line, __total_hpp_line); }