rmcvsdir.pp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. Copyright (c) 1999-2012 by Marco van de Voort and Free Pascal Core
  3. Recursively deletes .cvs and .svn directories essentially "exporting" a
  4. repository in place. Typically used when cleaning out old checkouts, to
  5. prepare for a GNU diff session with another checkout.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. }
  18. program rmcvsdir;
  19. uses
  20. sysutils;
  21. procedure deltree(const dirname : string);
  22. var
  23. rec : tsearchrec;
  24. begin
  25. writeln('Deleting ',dirname);
  26. if findfirst(dirname+'/*.*',faanyfile or fadirectory,rec)=0 then
  27. begin
  28. repeat
  29. if (rec.attr and fadirectory)<>0 then
  30. begin
  31. if (rec.name<>'.') and (rec.name<>'..') then
  32. deltree(dirname+'/'+rec.name)
  33. end
  34. else
  35. begin
  36. FileSetAttr(dirname+'/'+rec.name,faArchive);
  37. deletefile(dirname+'/'+rec.name);
  38. end;
  39. until findnext(rec)<>0;
  40. findclose(rec);
  41. end;
  42. rmdir(dirname);
  43. end;
  44. procedure searchcvsdir(const dirname : string);
  45. var
  46. rec : tsearchrec;
  47. begin
  48. writeln('Searching ',dirname);
  49. if findfirst(dirname+'/*.*',faanyfile or fadirectory,rec)=0 then
  50. begin
  51. repeat
  52. if (rec.attr and fadirectory)<>0 then
  53. begin
  54. if rec.name='CVS' then
  55. deltree(dirname+'/CVS')
  56. else if rec.name='.svn' then
  57. deltree(dirname+'/.svn')
  58. else if rec.name='.git' then
  59. deltree(dirname+'/.git')
  60. else
  61. if (rec.name<>'.') and (rec.name<>'..') then
  62. searchcvsdir(dirname+'/'+rec.name)
  63. end;
  64. until findnext(rec)<>0;
  65. findclose(rec);
  66. end;
  67. end;
  68. var
  69. para : string;
  70. begin
  71. if paramcount=0 then
  72. para:='.'
  73. else
  74. para:=paramstr(1);
  75. searchcvsdir(para);
  76. end.