Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7979847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:53:17+00:00 2026-06-04T09:53:17+00:00

I am currently writing a program that will eventually compare the files in two

  • 0

I am currently writing a program that will eventually compare the files in two directories and display the functions that have changed in each file. However, I have run into a problem when checking to see if what is in the directory is a file or is a sub-directory.

Right now, when I check to see if it is simply a directory with the -d check, it doesn’t catch any of the sub-directories. I have posted parts of my code below.

opendir newDir, $newDir;
my @allNewFiles = grep { $_ ne '.' and $_ ne '..'} readdir newDir;
closedir newDir;

opendir oldDir, $oldDir;
my @allOldFiles = grep { $_ ne '.' and $_ ne '..'} readdir oldDir;
closedir oldDir;


foreach (@allNewFiles) {
    if(-d $_) {
        print "$_ is not a file and therefore is not able to be compared\n\n";
    } elsif((File::Compare::compare("$newDir/$_", "$oldDir/$_") == 1)) {
        print "$_ in new directory $newDirName differs from old directory $oldDirName\n\n";
        print OUTPUTFILE "File: $_ has been update. Please check marked functions for differences\n";
        print OUTPUTFILE "\n\n";
        print OUTPUTFILE "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=\n\n";
    } elsif((File::Compare::compare("$newDir/$_", "$oldDir/$_") < 0)) {
        print "$_ found in new directory $newDirName but not in old directory $oldDirName\n";
        print "Entire file not printed to output file but instead only file name\n";
        print OUTPUTFILE "File: $_ is a new file!\n\n";
        print OUTPUTFILE "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=\n\n";
    }
 }

foreach (@allOldFiles) {
    if((File::Compare::compare("$newDir/$_", "$oldDir/$_") < 0)) {
        print "$_ found in old directory $oldDirName but not in new directory $newDirName\n\n";
    }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:53:19+00:00Added an answer on June 4, 2026 at 9:53 am

    As perldoc -f readdir states:

    If you’re planning to filetest the return values out of a readdir,
    you’d better prepend the directory in question. Otherwise, because we
    didn’t chdir there, it would have been testing the wrong file.

    if(-d "$newDir/$_") {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a program that needs to compare each file in an ArrayList
I am currently writing a program that will read part of the windows system
Hey guys, Im working with wpf 3d, im currently writing a program that will
I'm writing a program that, using Rijndael, will encrypt and decrypt files/folders using a
At the office we are currently writing an application that will generate XML files
I've been writing a C++ program that will eventually remove certain undesired formatting from
Since I am writing a program that will eventually run on Windows and Linux
I'm currently writing a java program that requires some Data to run. The data
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
Currently, I have a program that reads a file and uses an XMLTextWriter to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.