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.

108 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. delnode.c
  5. Abstract:
  6. Delnode routine for Setup.
  7. WARNING: the delnode routine in here is not multi-thread safe!
  8. Author:
  9. Ted Miller (tedm) August 1992
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. //
  14. // Put these out here so we don't consume huge stack space as we recurse.
  15. //
  16. TCHAR DelnodePattern[MAX_PATH];
  17. WIN32_FIND_DATA DelnodeFindData;
  18. VOID
  19. DelnodeRoutine(
  20. VOID
  21. )
  22. {
  23. LPTSTR PatternEnd;
  24. HANDLE FindHandle;
  25. //
  26. // Delete each file in the directory, then remove the directory itself.
  27. // If any directories are encountered along the way recurse to delete
  28. // them as they are encountered.
  29. //
  30. PatternEnd = DelnodePattern+lstrlen(DelnodePattern);
  31. lstrcat(DelnodePattern,TEXT("\\*"));
  32. FindHandle = FindFirstFile(DelnodePattern,&DelnodeFindData);
  33. if(FindHandle != INVALID_HANDLE_VALUE) {
  34. do {
  35. //
  36. // Form the full name of the file we just found.
  37. //
  38. lstrcpy(PatternEnd+1,DelnodeFindData.cFileName);
  39. if(DelnodeFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  40. //
  41. // The current match is a directory. Recurse into it unless
  42. // it's . or ...
  43. //
  44. if(lstrcmp(DelnodeFindData.cFileName,TEXT("." ))
  45. && lstrcmp(DelnodeFindData.cFileName,TEXT("..")))
  46. {
  47. DelnodeRoutine();
  48. }
  49. } else {
  50. //
  51. // The current match is not a directory -- so delete it.
  52. //
  53. SetFileAttributes(DelnodePattern,FILE_ATTRIBUTE_NORMAL);
  54. DeleteFile(DelnodePattern);
  55. }
  56. *(PatternEnd+1) = 0;
  57. } while(FindNextFile(FindHandle,&DelnodeFindData));
  58. FindClose(FindHandle);
  59. }
  60. //
  61. // Remove the directory we just emptied out.
  62. //
  63. *PatternEnd = 0;
  64. SetFileAttributes(DelnodePattern,FILE_ATTRIBUTE_NORMAL);
  65. RemoveDirectory(DelnodePattern);
  66. //
  67. // Note that the 'directory' might actually be a file.
  68. // Catch that case here.
  69. //
  70. DeleteFile(DelnodePattern);
  71. }
  72. VOID
  73. MyDelnode(
  74. IN LPCTSTR Directory
  75. )
  76. {
  77. lstrcpy(DelnodePattern,Directory);
  78. DelnodeRoutine();
  79. }