files2
Borland C++ Compiler 5.5
files2.c
#include
#include
#include
#include
#include
// プロトタイプ宣言 int files(const char *pcDir); int main(int argc, char **argv) { char acDir[_MAX_DIR]; int iDirLen; if (argc != 2) { fprintf(stderr, "usage: files2 dir\n"); return 1; } iDirLen = strlen(argv[1]); if (_MAX_DIR <= iDirLen) { fprintf(stderr, "error: dir too long\n"); return 1; } strcpy(acDir, argv[1]); if (0 < iDirLen && _mbsrchr(acDir, '\\') == acDir + iDirLen - 1) { acDir[iDirLen - 1] = '\0'; } files(acDir); return 0; } int files(const char *pcDir) { struct _finddata_t fd; char acPath[_MAX_PATH]; long lHandle; int iDirLen; iDirLen = strlen(pcDir); sprintf(acPath, "%s\\*.*", pcDir); lHandle = _findfirst(acPath, &fd); if (lHandle == -1) { fprintf(stderr, "error: _findfirst\n"); fprintf(stderr, "[%s]\n", pcDir); return -1; } do { if (fd.attrib & _A_SUBDIR) { if (strcmp(fd.name, ".") && strcmp(fd.name, "..")) { if (_MAX_DIR <= iDirLen + 1 + strlen(fd.name)) { fprintf(stderr, "error: dir too long\n"); fprintf(stderr, "[%s]\n", pcDir); fprintf(stderr, "[%s]\n", fd.name); continue; } sprintf(acPath, "%s\\%s", pcDir, fd.name); files(acPath); } } else { printf("%10u %s\\%s\n", fd.size, pcDir, fd.name); } } while (_findnext(lHandle, &fd) == 0); _findclose(lHandle); return 0; }
files2.exe