简体   繁体   中英

How to open multiple folders and compare the files in Perl?

I have a parent_folder_1 and many sub folders inside that. I also have parent_folder_2 and many sub folders inside that.

Sub folders contains .d files.

I have to get the number of parent_folders that the user wants to compare.

For example:

"How many parent_folders do you want to compare?"

If the user inputs 4, then the script should ask for paths of all the four parent_folders .

And, in one parent folder, inside one sub_folder, there is another folder called d folder which contains .d files.

I have to compare each .d file in all the four parent folders and have to put the results in an Excel spreadsheet as to which .d files are present in which parent folders.

If xxx.d sf present in parent folder1 and parent folder3 , then the output should be:

xxx.d  parent folder1 #this space is for parent folder2 if present# parentfolder3

This is the idea:

  • Use File::Find to traverse directories, sub-directories and files.
  • In wanted() , check for:

    -f $File::Find::name && $File::Find::name =~ /^.+\\.d$/

  • If the above condition evaluates to false, return; else, compare the files and populate the spreadsheet.

U can try using

#opening the directory
opendir (DIR, $directory) or die $!;
#reading the directory 
while (my $file = readdir(DIR)) {
print $file;}
#thus the giving the accessing the file in the way u would like to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM