Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program UCR;
- {$APPTYPE CONSOLE}
- uses
- Classes,
- Dialogs,
- IOUtils,
- SysUtils;
- function RemoveComments(const Path: string; const SearchRec: TSearchRec): Boolean;
- var
- fileName: string;
- s: TStrings;
- i: Integer;
- save: Boolean;
- begin
- fileName := IncludeTrailingPathDelimiter(Path) + SearchRec.Name;
- s := TStringList.Create;
- try
- s.LoadFromFile(fileName);
- i := 0;
- save := False;
- while i < s.Count do
- begin
- if Trim(s[i]) = '{ Private declarations }' then
- begin
- s.Delete(i);
- save := True;
- if (Trim(s[i-1]) = 'private') and (Trim(s[i]) = 'public') then
- begin
- Dec(i);
- s.Delete(i);
- end;
- Continue;
- end;
- if Trim(s[i]) = '{ Public declarations }' then
- begin
- s.Delete(i);
- save := True;
- if (Trim(s[i-1]) = 'public') and (Trim(s[i]) = 'end;') then
- begin
- Dec(i);
- s.Delete(i);
- end;
- Continue;
- end;
- Inc(i);
- end;
- if save then
- begin
- Writeln('Removed comments from unit: ', fileName);
- s.SaveToFile(fileName);
- end;
- finally
- s.Free;
- end;
- end;
- procedure Main;
- var
- dialog: TFileOpenDialog;
- begin
- dialog := TFileOpenDialog.Create(nil);
- dialog.Options := dialog.Options + [fdoPickFolders];
- if dialog.Execute then
- begin
- TDirectory.GetFiles(dialog.FileName, '*.pas',
- TSearchOption.soAllDirectories, RemoveComments);
- end;
- end;
- begin
- Main;
- Writeln('Press <Enter> to exit...');
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement