|
> ディレクトリ構成一覧表示のプログラムを教えてください。
> コマンドラインでコマンド名とドライブ名を入力するとそのドライブ内に
> あるディレクトリ構成一覧を表示したいのですがよくわかりません。
> いろいろ調べて「_dos_findfirst」を使うことはわかったのですが・・
Windows なら、16ビット Cランタイムの _dos_findfirst よりも、
32ビット Cランタイムの _findfirst を使ったほうが良いのではありませんか。
#include <stdio.h>
#include <string.h>
#include <io.h>
void dir(char *path, int len)
{
struct _finddata_t fd;
long handle;
strcpy(path + len, "\\*");
handle = _findfirst(path, &fd);
if (handle == -1) return;
do {
if ((fd.attrib & _A_SUBDIR)
&& strcmp(fd.name, ".")
&& strcmp(fd.name, "..")) {
sprintf(path + len, "\\%s", fd.name);
puts(path);
dir(path, len + 1 + strlen(fd.name));
}
} while (_findnext(handle, &fd) == 0);
}
int main(int argc, char **argv)
{
char path[4096];
if (argc == 2) {
strcpy(path, argv[1]);
dir(path, strlen(path));
}
return 0;
}
|