📄 main.c
字号:
//#######################################################################
//# To test the searchdir function , by fred.zeng
//# using stat funciton define in sys/stat.h
//#######################################################################
#include "searchdir.h"
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
// getstat() function is used to get the infomation of the file by name
struct stat * getstat(char * const filename)
{ struct stat * ststat = alloca(sizeof(struct stat)) ;
stat(filename,ststat);
return ststat;
}
// pf() is a callback function who will be invoked by listdir to process
// the displaying work of every filename and directory
void pf(char * const filename,int file_type)
{
//get the pointer to the information of the file by name
struct stat * pstat = getstat(filename);
if (file_type==T_FILE)
{
//display the filename and size
//printf("[%ld]",pstat->st_mode&S_IFMT);
printf("%s [File] Size = %ld byte\n",filename,pstat->st_size);
}
else
{
//printf("[%ld]",pstat->st_mode&S_IFMT);
printf("%s [DIR] \n",filename);
}
}
// The main() function
int main(int argc, char *const argv [])
{
if (argc==1) // no parameter means path=./
listdir("./",pf);
else
listdir(argv[1],pf);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -