Source code of Windows XP (NT5)
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.

199 lines
3.9 KiB

  1. /*
  2. Modifications:
  3. 07.08.96 Joe Holman Created to open all files for links.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <windows.h>
  9. #include <time.h>
  10. FILE* logFile;
  11. void Msg ( const char * szFormat, ... ) {
  12. va_list vaArgs;
  13. va_start ( vaArgs, szFormat );
  14. vprintf ( szFormat, vaArgs );
  15. vfprintf ( logFile, szFormat, vaArgs );
  16. va_end ( vaArgs );
  17. }
  18. void Header(argv)
  19. char* argv[];
  20. {
  21. time_t t;
  22. Msg ("\n=========== MCOPY =============\n");
  23. Msg("Log file: %s\n", argv[1]);
  24. time(&t);
  25. Msg("Time: %s",ctime(&t));
  26. Msg("================================\n\n");
  27. }
  28. void Usage()
  29. {
  30. printf("PURPOSE: Calls GetFileAttrEx on all files recursively.\n");
  31. printf("\n");
  32. printf("PARAMETERS:\n");
  33. printf("\n");
  34. printf("[LogFile] - Complete full path to append a log of actions and errors.\n");
  35. }
  36. void MyGetFileAttrEx ( char * szFile ) {
  37. BOOL bRC;
  38. WIN32_FILE_ATTRIBUTE_DATA wfd;
  39. GET_FILEEX_INFO_LEVELS gfi;
  40. bRC = GetFileAttributesEx ( szFile, 0, &wfd );
  41. if ( !bRC ) {
  42. Msg ( "ERROR: GetFileAttributesEx ( %s ), gle = %ld\n", szFile, GetLastError () );
  43. }
  44. else {
  45. Msg ( "[OK] GetFileAttributesEx ( %s )\n", szFile );
  46. }
  47. }
  48. BOOL GetFiles ( char * lastPath ) {
  49. WIN32_FIND_DATA wfd;
  50. HANDLE fHandle;
  51. BOOL bRC=TRUE;
  52. ULONG gle;
  53. char szSrc[256];
  54. char szPath[256];
  55. char szFind[256];
  56. char szSrcFile[256];
  57. strcpy ( szSrc, lastPath );
  58. sprintf ( szFind, "%s\\*.*", szSrc );
  59. fHandle = FindFirstFile ( szFind, &wfd );
  60. if ( fHandle == INVALID_HANDLE_VALUE ) {
  61. // An error occurred finding a file/directory.
  62. //
  63. Msg ( "ERROR R FindFirstFile FAILED, szFind = %s, GLE = %ld\n",
  64. szFind, GetLastError() );
  65. return (FALSE);
  66. }
  67. else {
  68. // Since this is the first time finding a directory,
  69. // go to the loops code that makes the same directory on the
  70. // destination.
  71. //
  72. goto DIR_LOOP_ENTRY;
  73. }
  74. do {
  75. DIR_CONTINUE:;
  76. bRC = FindNextFile ( fHandle, &wfd );
  77. if ( !bRC ) {
  78. // An error occurred with FindNextFile.
  79. //
  80. gle = GetLastError();
  81. if ( gle == ERROR_NO_MORE_FILES ) {
  82. //Msg ( "ERROR_NO_MORE_FILES...\n" );
  83. FindClose ( fHandle );
  84. return (TRUE);
  85. }
  86. else {
  87. Msg ( "ERROR R FindNextFile FAILED, GLE = %ld\n",
  88. GetLastError() );
  89. FindClose ( fHandle );
  90. exit ( 1 );
  91. }
  92. }
  93. else {
  94. DIR_LOOP_ENTRY:;
  95. // Msg ( "wfd.cFileName = %s\n", wfd.cFileName );
  96. // If not directory, don't just continue.
  97. //
  98. if ( (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 ) {
  99. sprintf ( szSrcFile, "%s\\%s", szSrc, wfd.cFileName );
  100. MyGetFileAttrEx ( szSrcFile );
  101. goto DIR_CONTINUE;
  102. }
  103. // Don't do anything with . and .. directory entries.
  104. //
  105. if (!strcmp ( wfd.cFileName, "." ) ||
  106. !strcmp ( wfd.cFileName, "..") ) {
  107. //Msg ( "Don't do anything with . or .. dirs.\n" );
  108. goto DIR_CONTINUE;
  109. }
  110. sprintf ( szPath, "%s\\%s", szSrc, wfd.cFileName );
  111. //Msg ( "szPath = %s\n", szPath );
  112. // Keep recursing down the directories.
  113. //
  114. GetFiles ( szPath );
  115. }
  116. } while ( bRC );
  117. return ( TRUE );
  118. }
  119. __cdecl main(int argc, char * argv[] ) {
  120. BOOL b;
  121. if (argc!=2) {
  122. Usage();
  123. return(1);
  124. }
  125. if ((logFile=fopen(argv[1],"a"))==NULL) {
  126. printf("ERROR Couldn't open log file %s\n",argv[1]);
  127. return(1);
  128. }
  129. Header(argv);
  130. GetFiles ( "." );
  131. fclose(logFile);
  132. return(0);
  133. }