- 论坛徽章:
- 12
|
在windows,很久之前写的了,MinGW
g++ treeT.cpp -municode -D_UNICODE -o treeT_UNI
or
g++ treeT.cpp -o treeT_ASC
- #include <iostream>
- #include <cstdio>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <dirent.h>
- #include <cwchar>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <cstring>
- #define NAME_MAX 1024
- void func(wchar_t path[]);
- static FILE * fp = _wfopen(L"tree_.txt", L"wb");
- int wmain(int argc, wchar_t *argv[] )
- {
- wchar_t pth[] = L"D:\\Extra";
- func(pth);
- fclose(fp);
- return 0;
- }
- void func(wchar_t path[])
- {
- _WDIR * a = _wopendir(path);
- _wdirent * dp;
- _WDIR * aa;
- struct stat stbuf;
- wchar_t fullpath[NAME_MAX] = L"";
- while (dp = _wreaddir(a))
- {
- if (
- wcscmp(dp->d_name, L".") == 0
- || wcscmp(dp->d_name, L"..") == 0
- )
- {
- continue;
- }
- swprintf(fullpath, L"%ls\\%ls", path, dp->d_name);
- wstat(fullpath, &stbuf);
- if ( (stbuf.st_mode & S_IFMT) == S_IFDIR )
- {
- func( fullpath );
- }
- else
- {
- //output file list
- fwprintf(stderr, L"%ld\t%ls\r\n", stbuf.st_mtime, fullpath );
- }
- }
- _wclosedir(a);
-
- }
复制代码 |
|