97 lines
2.4 KiB
C
97 lines
2.4 KiB
C
|
/*
|
|||
|
Program: folder-info.c (Report comments/bugs to chikh@yuntech.edu.tw)
|
|||
|
Function: <EFBFBD>H<EFBFBD><EFBFBD><EFBFBD>j<EFBFBD><EFBFBD><EFBFBD>覡<EFBFBD><EFBFBD><EFBFBD>ܫ<EFBFBD><EFBFBD>w<EFBFBD>ؿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҧ<EFBFBD><EFBFBD>ɮP<EFBFBD>ɮק<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>T
|
|||
|
Note: <EFBFBD><EFBFBD><EFBFBD>{<EFBFBD><EFBFBD><EFBFBD>ϥ<EFBFBD>dirent.h<EFBFBD>A<EFBFBD>Ӽ<EFBFBD><EFBFBD>Y<EFBFBD>ɩw<EFBFBD>q<EFBFBD>ؿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>c<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><EFBFBD>A<EFBFBD>A<EFBFBD>Ӽ<EFBFBD><EFBFBD>Y<EFBFBD>ɦ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include
|
|||
|
*/
|
|||
|
|
|||
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
#include <string.h>
|
|||
|
#include <dirent.h>
|
|||
|
|
|||
|
#define MaxSize 256
|
|||
|
|
|||
|
int chopPos(char *dirPath)
|
|||
|
{
|
|||
|
int i, count, len = strlen(dirPath);
|
|||
|
|
|||
|
if (dirPath[len-1] != '\\') {
|
|||
|
dirPath[len] = '\\';
|
|||
|
dirPath[len+1] = '\0';
|
|||
|
}
|
|||
|
|
|||
|
for (i = len-1, count = 0; i > 0 && count < 2; i--)
|
|||
|
if (dirPath[i]=='\\') count++;
|
|||
|
|
|||
|
return i+2;
|
|||
|
}
|
|||
|
|
|||
|
void showDirectory(char *folderPath, int level)
|
|||
|
{
|
|||
|
DIR *dpdf;
|
|||
|
struct dirent *epdf;
|
|||
|
char fileName[2*MaxSize], nextLevelDir[128][768], *pstr, indent[2*MaxSize]={0};
|
|||
|
long fileSize, fileCount, i, dirCount = 0;
|
|||
|
FILE *fp;
|
|||
|
|
|||
|
if ((dpdf=opendir(folderPath)) == NULL) { /* <20>}<7D>ҥؿ<D2A5><D8BF><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>c */
|
|||
|
printf("<EFBFBD>ؿ<EFBFBD>%s<><73><EFBFBD>s<EFBFBD>b!\n",folderPath);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
pstr = folderPath+chopPos(folderPath);
|
|||
|
if (level==0) {
|
|||
|
printf("%s\n",pstr);
|
|||
|
sprintf(indent,"%s%s",indent,"| ");
|
|||
|
}
|
|||
|
else {
|
|||
|
for (i = 0; i < level-1; i++)
|
|||
|
sprintf(indent,"%s%s",indent,"| ");
|
|||
|
printf("%s+---%s\n",indent,pstr);
|
|||
|
sprintf(indent,"%s%s",indent,"| | ");
|
|||
|
}
|
|||
|
|
|||
|
while (epdf = readdir(dpdf)) { /* Ū<><C5AA><EFBFBD>ɮשҦb<D2A6>ؿ<EFBFBD><D8BF>A<EFBFBD>u<EFBFBD>ndpdf<64>ҫ<EFBFBD><D2AB><EFBFBD><EFBFBD>e<EFBFBD><65><EFBFBD>šA<C5A1>Y<EFBFBD>N<EFBFBD><4E><EFBFBD>ۦ<EFBFBD><DBA6>ɮצs<D7A6>b<EFBFBD>A<EFBFBD>]<5D><><EFBFBD>i<EFBFBD>J<EFBFBD>j<EFBFBD><6A><EFBFBD>B<EFBFBD>z */
|
|||
|
if (strcmp(epdf->d_name,".")==0 || strcmp(epdf->d_name,"..")==0) continue; /* <20>ư<EFBFBD><C6B0>ؿ<EFBFBD><D8BF><EFBFBD><EFBFBD><EFBFBD> . <20>P .. (<28><><EFBFBD>U<EFBFBD>ؿ<EFBFBD><D8BF>P<EFBFBD>W<EFBFBD>@<40>h<EFBFBD>ؿ<EFBFBD>) */
|
|||
|
sprintf(fileName,"%s%s",folderPath,epdf->d_name); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|+<2B>ɦW
|
|||
|
if ((fp=fopen(fileName,"rb")) == NULL) { // <20>}<7D><><EFBFBD>ɮסA<D7A1>}<7D>ɼҦ<C9BC><D2A6><EFBFBD>"<22><><EFBFBD>r<EFBFBD>D<EFBFBD><44><EFBFBD>r<EFBFBD>q<EFBFBD>Y"
|
|||
|
sprintf(nextLevelDir[dirCount++],"%s\\",fileName);
|
|||
|
}
|
|||
|
else {
|
|||
|
fclose(fp);
|
|||
|
printf("%s%s\n",indent,epdf->d_name);
|
|||
|
fileCount++;
|
|||
|
}
|
|||
|
}
|
|||
|
closedir(dpdf); /* <20><><EFBFBD><EFBFBD><EFBFBD>ؿ<EFBFBD><D8BF><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>c */
|
|||
|
if (fileCount > 0) {
|
|||
|
if (level==0)
|
|||
|
printf("%s(<28><><EFBFBD>W<EFBFBD><57>%d<>ɮ<EFBFBD>)\n%s\n",indent,fileCount,indent);
|
|||
|
else {
|
|||
|
printf("%s(<28><><EFBFBD>W<EFBFBD><57>%d<>ɮ<EFBFBD>)\n",indent,fileCount);
|
|||
|
for (i = 0; i < strlen(indent)-4; i++) putchar(indent[i]);
|
|||
|
printf("\n");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (dirCount > 0) {
|
|||
|
for (i = 0; i < dirCount; i++)
|
|||
|
showDirectory(nextLevelDir[i],level+1);
|
|||
|
}
|
|||
|
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
char directoryPath[MaxSize];
|
|||
|
|
|||
|
printf("\n<EFBFBD><EFBFBD><EFBFBD>J<EFBFBD>ؿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>| ==> ");
|
|||
|
scanf("%255[^\n]%*c",directoryPath,0);
|
|||
|
printf("<EFBFBD>ɮק<EFBFBD>%s<><73><EFBFBD>T<EFBFBD>p<EFBFBD>U\n",directoryPath);
|
|||
|
showDirectory(directoryPath,0);
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|