By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

seraching binary files by their version

P: 4
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.
Mar 12 '08 #1
Share this Question
Share on Google+
1 Reply


P: 23
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.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use File::Find;
  4. use File::Basename;
  5. use File::Spec::Unix;
  6.  
  7. my $top_dir = $ARGV[0];
  8. my $dir_path = File::Spec->rel2abs($top_dir);
  9. my @file_list = ();
  10. my @all_file = Get_Dirs_Files($dir_path);
  11. foreach my $item (@all_file) { 
  12.   push(@file_list,"$item") if($item =~ m/.*\.dll$|.*\.exe$/);
  13. }
  14.  
  15. @file_list = map{"$dir_path/"."$_"} @file_list;
  16.  
  17. foreach my $my_file (@file_list) {
  18.   my ($file_name,$dir,$file_type) = fileparse($my_file,qr"\..*");
  19.   print "$my_file\n";
  20.   #/use the system command to find out the version of the dll file here/
  21. }
  22.  
  23. #------------------------------------------------------
  24. # Get all the files from the directory recursively 
  25. #------------------------------------------------------
  26.  
  27. sub Get_Dirs_Files {
  28.   my $cur_folder = shift;
  29.   my @all;
  30.   chdir($cur_folder) or die("Cannot access folder $cur_folder");
  31.   my @both = glob("*");
  32.   my @folders;
  33.   foreach my $item (@both) {
  34.     if(-d $item) { 
  35.       push(@folders,"$item");
  36.     } 
  37.     else { 
  38.       push(@all,"$item");
  39.     }
  40.   }
  41.  
  42.   foreach my $this_folder (@folders) {
  43.     push(@all,"$this_folder/");
  44.  
  45.     my $full_path = "$cur_folder/$this_folder";
  46.     my @deep_items = Get_Dirs_Files($full_path); # :RECURSION:
  47.     foreach my $item (@deep_items) {
  48.       push(@all,"$this_folder/$item");
  49.     }
  50.   }
  51.   return @all;
  52. }
  53.  
  54.  
-Manimaran
Mar 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.