Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. enumtree.c
  5. Abstract:
  6. Performs a test of the file enumeration code.
  7. Author:
  8. Jim Schmidt (jimschm) 14-Jan-1998
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. #include "pch.h"
  13. VOID
  14. HelpAndExit (
  15. VOID
  16. )
  17. {
  18. printf ("Command line syntax:\n\n"
  19. "enumtree [-d|-f] [-i] [-p:pattern] [-s] [-x:ext] [-x:ext] [-x:...] <root>\n\n"
  20. "<root> Specifies the root path to enumerate (required)\n"
  21. "-d Specifies dirs should be recursed before files are listed\n"
  22. "-f Specifies files should be listed before dirs are recursed\n"
  23. "-i Specifies that the scan will be in depth first\n"
  24. "-p Specifies a pattern of files to find\n"
  25. "-s SLM mode (outputs files not read-only)\n"
  26. "-e Specifies file to exclused from the -s option\n"
  27. "-x Specifies extension to exclude from the -s option\n"
  28. );
  29. exit(0);
  30. }
  31. BOOL
  32. pScanGrowListForStr (
  33. IN PGROWLIST Exclusions,
  34. IN PCTSTR SearchStr
  35. )
  36. {
  37. UINT i;
  38. UINT Size;
  39. PCTSTR Str;
  40. Size = GrowListGetSize (Exclusions);
  41. for (i = 0 ; i < Size ; i++) {
  42. Str = GrowListGetString (Exclusions, i);
  43. if (StringIMatch (SearchStr, Str)) {
  44. return TRUE;
  45. }
  46. }
  47. return FALSE;
  48. }
  49. HANDLE g_hHeap;
  50. HINSTANCE g_hInst;
  51. INT
  52. __cdecl
  53. _tmain (
  54. INT argc,
  55. TCHAR *argv[]
  56. )
  57. {
  58. TREE_ENUM e;
  59. PCTSTR RootPath;
  60. PCTSTR FilePattern;
  61. INT i;
  62. UINT u;
  63. BOOL DirsFirst = TRUE;
  64. BOOL DepthFirst = FALSE;
  65. UINT Files, Dirs;
  66. BOOL SlmMode = FALSE;
  67. PCTSTR Ext = NULL;
  68. GROWLIST FileExclusions = GROWLIST_INIT;
  69. GROWLIST ExtExclusions = GROWLIST_INIT;
  70. RootPath = NULL;
  71. FilePattern = NULL;
  72. g_hHeap = GetProcessHeap();
  73. for (i = 1 ; i < argc ; i++) {
  74. if (argv[i][0] == TEXT('-') || argv[i][0] == TEXT('/')) {
  75. switch (_totlower (argv[i][1])) {
  76. case TEXT('d'):
  77. DirsFirst = TRUE;
  78. break;
  79. case TEXT('f'):
  80. DirsFirst = FALSE;
  81. break;
  82. case TEXT('i'):
  83. DepthFirst = TRUE;
  84. break;
  85. case TEXT('p'):
  86. if (argv[i][2] == ':') {
  87. FilePattern = &argv[i][3];
  88. } else if (i + 1 < argc) {
  89. FilePattern = argv[i + 1];
  90. } else {
  91. HelpAndExit();
  92. }
  93. break;
  94. case TEXT('x'):
  95. if (argv[i][2] == ':') {
  96. Ext = &argv[i][3];
  97. } else if (i + 1 < argc) {
  98. Ext = argv[i + 1];
  99. } else {
  100. HelpAndExit();
  101. }
  102. GrowListAppendString (&ExtExclusions, Ext);
  103. break;
  104. case TEXT('e'):
  105. if (argv[i][2] == ':') {
  106. Ext = &argv[i][3];
  107. } else if (i + 1 < argc) {
  108. Ext = argv[i + 1];
  109. } else {
  110. HelpAndExit();
  111. }
  112. GrowListAppendString (&FileExclusions, Ext);
  113. break;
  114. case TEXT('s'):
  115. SlmMode = TRUE;
  116. break;
  117. default:
  118. HelpAndExit();
  119. }
  120. }
  121. else if (RootPath) {
  122. HelpAndExit();
  123. }
  124. else {
  125. RootPath = argv[i];
  126. }
  127. }
  128. if (!RootPath) {
  129. HelpAndExit();
  130. }
  131. Files = 0;
  132. Dirs = 0;
  133. if (EnumFirstFileInTreeEx (&e, RootPath, FilePattern, DirsFirst, DepthFirst, FILE_ENUM_ALL_LEVELS)) {
  134. do {
  135. if (e.Directory) {
  136. Dirs++;
  137. } else {
  138. Files++;
  139. }
  140. if (!SlmMode) {
  141. for (u = 0 ; u < e.Level ; u++) {
  142. _tprintf (TEXT(" "));
  143. }
  144. _tprintf (TEXT("%s\n"), e.Name);
  145. } else {
  146. if (!e.Directory && !(e.FindData->dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
  147. Ext = GetFileExtensionFromPath (e.Name);
  148. if (!Ext) {
  149. Ext = S_EMPTY;
  150. }
  151. if (!pScanGrowListForStr (&ExtExclusions, Ext) &&
  152. !pScanGrowListForStr (&FileExclusions, e.Name)
  153. ) {
  154. _tprintf (TEXT("%s\n"), e.SubPath);
  155. }
  156. }
  157. }
  158. } while (EnumNextFileInTree (&e));
  159. }
  160. if (!SlmMode) {
  161. _tprintf (TEXT("\nFiles: %u\nDirs: %u\n"), Files, Dirs);
  162. }
  163. FreeGrowList (&ExtExclusions);
  164. return 0;
  165. }