Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Compare all the files in Folders and Subfolders

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

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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:
    [code]
    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;
    [/code]
  • pascal-coderpascal-coder Posts: 40Member
    : : 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:
    : [code]
    : 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;
    : [/code]
    :



    Thanks ill try

  • pascal-coderpascal-coder Posts: 40Member
    : : : 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:
    : : [code]
    : : 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;
    : : [/code]
    : :
    :
    :
    :
    : 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 ?

  • zibadianzibadian Posts: 6,349Member
    : : : : 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:
    : : : [code]
    : : : 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;
    : : : [/code]
    : : :
    : :
    : :
    : :
    : : 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:
    [code]
    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;
    [/code]
  • antony09antony09 Posts: 2Member
    This post has been deleted.
  • antony09antony09 Posts: 2Member
    This post has been deleted.
Sign In or Register to comment.