如何统计桌面上的目录数量?我只得到文件夹列表,但我只需要文件夹的数量,我完全不明白该怎么做!:(
PS 不是文件,只有文件夹
谢谢你!
以下C代码将列出文件和目录的数量,并且比linux find命令快4倍。我只需要文件夹的数量,对文件数量甚至列出它们都不感兴趣。有没有一种方法可以优化以下代码并使之更高效?
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
void listdir(char *path, size_t size) {
    DIR *dir;
    struct dirent *entry;
    size_t len = strlen(path);
    if (!(dir = opendir(path))) {
        fprintf(stderr, "path not found: %s: %s\n",
                path, strerror(errno));
        return;
    }
    puts(path);
    while ((entry = readdir(dir)) != NULL) {
        char *name = entry->d_name;
        if (entry->d_type == DT_DIR) {
            if (!strcmp(name, ".") || !strcmp(name, ".."))
                continue;
            if (len + strlen(name) + 2 > size) {
                fprintf(stderr, "path too …Run Code Online (Sandbox Code Playgroud) 它在哪里?我尝试了XCode 8的旧答案,它不在那里.为什么Apple让我们很难在模拟器中看到我们的应用程序的沙箱?
我需要使用Perl列出存储在数组中的所有目录和子目录.
例如:
$array[0] = '/home';
$array[1] = '/home/ali';
$array[2] = '/home/perl';
$array[3] = '/home/stackoverflow';
$array[4] = '/home/ali/desktop';
$array[5] = '/home/ali/sub';
$array[6] = '/home/stackoverflow/new';
Run Code Online (Sandbox Code Playgroud)