- 论坛徽章:
- 1
|
请教大家~~有关"写目录"的函数是哪些哪~~~是写哦~~
- /*
- *
- * By Miaoquan
- */
- #include <stdio.h>;
- #include <dirent.h>;
- #include <sys/types.h>;
- #include <sys/stat.h>;
- #include "error.c"
- int main(int argc, char *argv[])
- {
- DIR *dp;
- struct dirent *dirp;
- struct stat st;
- if(argc!=2)
- {
- err_quit("Usage: dirpath!\n");
- }
- if(stat(argv[1],&st)==-1)
- {
- err_quit("Get stat failed!\n");
- }
- if((st.st_mode & S_IFMT)==S_IFDIR)
- {
- printf("Dir :%s\n\n",argv[1]);
- }
- else
- {
- err_quit("it is no a dir\n");
- }
- if((dp=opendir(argv[1]))==NULL)
- {
- err_quit("open dir failed!");
- }
- while((dirp=readdir(dp))!=NULL)
- {
- printf("%s\n",dirp->;d_name);
- }
- exit(0);
- }
复制代码- /*
- *
- * By Miaoquan
- */
- #include <stdio.h>;
- #include <errno.h>;
- void err_quit(char *word)
- {
- printf("%s\n",word);
- exit(1);
- }
- void su_quit(char *word)
- {
- printf("%s\n",word);
- exit(0);
- }
- void bug(char *word,int n)
- {
- perror(word);
- exit(n);
- }
复制代码 |
|