C 語言編寫的Windows下 類似Linux 的 ls(list) 命令.
命令格式:
ls directory_name (directory_name 就是文件夾目錄)
如使用有問題, 歡迎提問.
代碼如下
- int main(int argc, char *argv[])
- {
- DIR *dp;
- struct dirent *dirp;
-
-
- // check the enter
- if (argc != 2)
- {
- printf("Error: enter false!!!!\nRetry:");
- return 1;
- }
-
- // check the director
- if ( (dp = opendir(argv[1]) ) == NULL)
- {
- printf("The is not %s directory", argv[1]);
- return 1;
- }
-
- // list the file name
- while ( (dirp = readdir(dp)) != NULL)
- {
- printf("%s\n", dirp -> d_name);
- }
-
- closedir(dp);
- return 0;
- }