gpt4 book ai didi

apache - 是否可以使用 apache 可移植运行时获取目录中的文件列表?

转载 作者:行者123 更新时间:2023-12-02 09:17:36 24 4
gpt4 key购买 nike

我需要使用 APR 获取目录中的文件列表。我该怎么做?我在文档中寻找答案,但一无所获。谢谢!

最佳答案

你想要的函数是apr_dir_open。我发现头文件是 APR 的最佳文档

http://apr.apache.org/docs/apr/1.4/group_apr_dir.html

这是读取“.”的示例。并报告错误(如果遇到)

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <apr.h>
#include <apr_errno.h>
#include <apr_pools.h>
#include <apr_file_info.h>

static void apr_fatal(apr_status_t rv);

int main(void)
{
apr_pool_t *pool;
apr_status_t rv;

// Initialize APR and pool
apr_initialize();
if ((rv = apr_pool_create(&pool, NULL)) != APR_SUCCESS) {
apr_fatal(rv);
}

// Open the directory
apr_dir_t *dir;
if ((rv = apr_dir_open(&dir, ".", pool)) != APR_SUCCESS) {
apr_fatal(rv);
}

// Read the directory
apr_finfo_t finfo;
apr_int32_t wanted = APR_FINFO_NAME | APR_FINFO_SIZE;
while ((rv = apr_dir_read(&finfo, wanted, dir)) == APR_SUCCESS) {
printf("%s\t%10"PRIu64"\n", finfo.name, (uint64_t)finfo.size);
}
if (!APR_STATUS_IS_ENOENT(rv)) {
apr_fatal(rv);
}

// Clean up
apr_dir_close(dir);
apr_pool_destroy(pool);
apr_terminate();
return 0;
}

static void apr_fatal(apr_status_t rv)
{
const int bufsize = 1000;
char buf[bufsize+1];
printf("APR Error %d: %s\n", rv, apr_strerror(rv, buf, bufsize));
exit(1);
}

关于apache - 是否可以使用 apache 可移植运行时获取目录中的文件列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19907411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com