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

  • Home
  • SEARCH
  • 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 1005153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:14:56+00:00 2026-05-16T08:14:56+00:00

I am currently writing a quick script in Ruby that goes through all the

  • 0

I am currently writing a quick script in Ruby that goes through all the contents of two folders, and returns a list of all the files that are not in either of the two folders.
Currently what I am doing is storing the paths of all the files of each directory in an array:

Find.find(dir1) do |path|
  if File.file?(path)
    directory1_files << path # Add path to an array of file_paths for the 1st directory.
  end
end # I repeat the process for the second directory and store their paths in an array called directory2_files.

The problem I am having is that when I try and subtract the two arrays (larger array – small array) to get the remaining files, I get an empty array. Reason I get this is because the full paths are trying to be subtracted instead of just the basenames. Ex: ~/folder1/file.txt != ~/folder2/file.txt
How can I find if a file with the same name is in two folders, and remove it from a list so the only files remaining are the ones not present in both folders?

  • 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-05-16T08:14:57+00:00Added an answer on May 16, 2026 at 8:14 am

    Since you know the paths to both folders (i.e. dir1 and dir2) I’d suggest to to calculate paths relative to them, so that later you could compare relative paths (effectively ignoring the ~/folder1 part of the path). Use dictionaries to map between relative and absolute paths (so that you could remove them).

    Something like this:

    dir1 = '~/folder1'
    directory1_files = {}
    
    Find.find(dir1) do |path|
      if File.file?(path)
        relative_path = path[dir1.length, path.length]
        directory1_files[relative_path] = path
      end
    end
    

    Then, whenever you have directory1_files and directory2_files, compare their .keys in order to find the differences.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can take your current query, and add a UNION… May 16, 2026 at 12:44 pm
  • Editorial Team
    Editorial Team added an answer There is no cross-platform API for this. On Linux you… May 16, 2026 at 12:44 pm
  • Editorial Team
    Editorial Team added an answer Overload Attach for different numbers of parameters in the member… May 16, 2026 at 12:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

So i'm writing a quick perl script that cleans up some HTML code and
I'm currently writing a piece of code that does some searches which returns IDisposable
I'm currently writing a small python app that embeds cherrypy and django using py2app.
I'm currently writing a quick solution for Euler Problem #4 where one must find
I'm currently writing a quick custom encoding method where I take a stamp a
a quick, simple question from me about for-loops. Situation I'm currently writing some high-performance
I am currently writing an application that needs to pull data from an XHTML
I have a rails site that allows authentication through OAuth (I use Restful Authentication
I am currently writing my first Android application and I keep running into references
I'm currently writing a JNI project where I'm getting the following error log when

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.