C file list > 공지사항

본문 바로가기
사이트 내 전체검색

공지사항

C file list

페이지 정보

profile_image
작성자 최고관리자
댓글 0건 조회 24회 작성일 25-05-13 09:17

본문

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>

#define TARGET_DIR "./target_folder"      // 対象のフォルダ
#define OUTPUT_FILE "file_list.txt"      // 出力ファイル名

int main() {
    DIR *dir;
    struct dirent *entry;
    char output_path[1024];

    // 出力ファイルのパスを作成(例: ./target_folder/file_list.txt)
    snprintf(output_path, sizeof(output_path), "%s/%s", TARGET_DIR, OUTPUT_FILE);

    FILE *fp = fopen(output_path, "w");
    if (!fp) {
        perror("出力ファイル作成失敗");
        return 1;
    }

    dir = opendir(TARGET_DIR);
    if (!dir) {
        perror("ディレクトリオープン失敗");
        fclose(fp);
        return 1;
    }

    while ((entry = readdir(dir)) != NULL) {
        // "." と ".." を除外
        if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
            continue;

        // 出力ファイル自身は除外
        if (strcmp(entry->d_name, OUTPUT_FILE) == 0)
            continue;

        fprintf(fp, "%s\n", entry->d_name);
    }

    closedir(dir);
    fclose(fp);

    printf("ファイルリストを %s に出力しました\n", output_path);
    return 0;
}

댓글목록

등록된 댓글이 없습니다.

Total 13건 77 페이지
공지사항 목록
번호 제목 글쓴이 조회 날짜
게시물이 없습니다.

검색


회사소개 개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 070-4218-6433 東京都新宿区新宿2-12-13
E-Mail:webinfo_ok@yn-giin.com

Copyright © WWW.YN-GIIN.COM All rights reserved.