: : : : I would like to compare all the files in a Folder(and in its Subfolders) with a similar Folder. Then I would like to rename files with teh same size to match the ones in the other folder.
: : : :
: : : : I cant manage, could someone help me?
: : : : Thanks in advance
: : : :
: : : Use FindFirst(), FindNext() and FindClose() to enumerate through one of the folders and create a list of all the files in that folder. Then use the same functions on the other and match its sizes and names against the list, and if necessary use RenameFile() to perform the rename. This works for 1 folder, it is easy to include the subfolders by making the routine recursive. Here's the initial setup:
: : :
: : : procedure RenameAll(path1, path2: string; ...);
: : : begin
: : : if FindFirst(path1) = 0 then repeat
: : : if (found "file" is directory) and (name[1] <> '.') then
: : : // found a directory, but not the current (.) or parent directory (..)
: : : RenameAll(path1+name, path2+name);
: : : else
: : : Add file to list
: : : until FindNext() <> 0;
: : : FindClose();
: : : // List complete now process it
: : : if FindFirst(path2) = 0 then repeat
: : : if (found "file" is directory) and (name[1] <> '.') then
: : : // found a directory, but not the current (.) or parent directory (..)
: : : RenameAll(path1+name, path2+name);
: : : else
: : : find file in list and rename it if necessary
: : : until FindNext() <> 0;
: : : FindClose();
: : : end;
: : :
: : :
: :
: :
: :
: : Thanks ill try
: :
: :
:
: I tryed, but I didn't get that FindFirst() stuff to work. Could someone maybe post a working example of the Find... bit ?
:
:
This code finds all the text files on the C: drive, and shows them in a memo:
procedure TForm1.Scan(Path: string);
var
SR: TSearchRec;
begin
if FindFirst(Path+'*.txt', faAnyFile, SR) = 0 then repeat
if (SR.Attr and faDirectory = faDirectory) and (SR.Name[1] <> '.') then
Scan(IncludeTrailingBackSlash(Path+SR.Name))
else
Memo1.Lines.Add(Path+SR.Name);
until FindNext(SR) <> 0;
FindClose(SR);
end;
procedure TForm1.Button1Click();
begin
Scan('c:\');
end;