seraching binary files by their version

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • upendrasingh
    New Member
    • Feb 2008
    • 4

    seraching binary files by their version

    hi all,

    suppose I have a directory with lots of levels of subdirectories within that. any of the sub directory may contain .exe and .dll files. different directories may contain dlls and exe's with same name but they differ in their versions. now i want to write a perl script that can search a dll or exe with a given name having a particular version. for example..

    lets there is a directory "root" with 4 subdir a,b,c,d. all of them contain a dll file named "myfile.dll ", the versions are say as follows

    directory dll name version

    a myfile.dll 1.1.0

    b -do- 1.1.1

    c - do- 1.1.2

    d -do- 1.1.3



    now I give as an input to my script "myfile.dll " and "1.1.2" then it shoud return me the myfile.dll file of directory "C"

    I hope this is clear to u all..

    waiting for your replies

    thanks.
  • manimarank
    New Member
    • Jul 2007
    • 23

    #2
    use the dos command to find the version of the dll or exe file in the foreach loop
    with the the perl system command or exec command.

    [CODE=perl]
    use strict;
    use warnings;
    use File::Find;
    use File::Basename;
    use File::Spec::Uni x;

    my $top_dir = $ARGV[0];
    my $dir_path = File::Spec->rel2abs($top_d ir);
    my @file_list = ();
    my @all_file = Get_Dirs_Files( $dir_path);
    foreach my $item (@all_file) {
    push(@file_list ,"$item") if($item =~ m/.*\.dll$|.*\.ex e$/);
    }

    @file_list = map{"$dir_path/"."$_"} @file_list;

    foreach my $my_file (@file_list) {
    my ($file_name,$di r,$file_type) = fileparse($my_f ile,qr"\..*");
    print "$my_file\n ";
    #/use the system command to find out the version of the dll file here/
    }

    #------------------------------------------------------
    # Get all the files from the directory recursively
    #------------------------------------------------------

    sub Get_Dirs_Files {
    my $cur_folder = shift;
    my @all;
    chdir($cur_fold er) or die("Cannot access folder $cur_folder");
    my @both = glob("*");
    my @folders;
    foreach my $item (@both) {
    if(-d $item) {
    push(@folders," $item");
    }
    else {
    push(@all,"$ite m");
    }
    }

    foreach my $this_folder (@folders) {
    push(@all,"$thi s_folder/");

    my $full_path = "$cur_folde r/$this_folder";
    my @deep_items = Get_Dirs_Files( $full_path); # :RECURSION:
    foreach my $item (@deep_items) {
    push(@all,"$thi s_folder/$item");
    }
    }
    return @all;
    }

    [/CODE]

    -Manimaran

    Comment

    Working...