Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Compare all the files in Folders and Subfolders Posted by pascal-coder on 26 Sept 2006 at 5:32 AM
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
Report
Re: Compare all the files in Folders and Subfolders Posted by zibadian on 26 Sept 2006 at 6:31 AM
: 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;

Report
Re: Compare all the files in Folders and Subfolders Posted by pascal-coder on 26 Sept 2006 at 7:15 AM
: : 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

Report
Re: Compare all the files in Folders and Subfolders Posted by pascal-coder on 26 Sept 2006 at 8:45 AM
: : : 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 ?

Report
Re: Compare all the files in Folders and Subfolders Posted by zibadian on 26 Sept 2006 at 2:58 PM
: : : : 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;

Report
This post has been deleted. Posted by antony09 on 22 Jan 2010 at 5:16 AM
This post has been deleted.
Report
This post has been deleted. Posted by antony09 on 22 Jan 2010 at 5:18 AM
This post has been deleted.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.