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 3304634
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:04:58+00:00 2026-05-17T21:04:58+00:00

can anyone please suggest a method (ruby, python or dos preferable) to remove only

  • 0

can anyone please suggest a method (ruby, python or dos preferable) to remove only the different files and sub-folders between two given folders?

I need it to recurse through sub-directories and delete everything that is different.

I don’t wanna have to install anything, so a script would be great.

Thanks in advance

  • 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-17T21:04:59+00:00Added an answer on May 17, 2026 at 9:04 pm

    This is the kind of thing I have done when I wanted to diff directories:

    #!/usr/bin/env python
    
    import os, os.path
    import stat
    
    def traverse_path(start_dir='.'):
        for root, dirs, files in os.walk(start_dir, topdown=False):
            for f in files:
                complete_path = os.path.join(root, f)
                try:
                    m = os.stat(complete_path)[stat.ST_MODE]
                    if stat.S_ISREG(m):
                        yield complete_path[len(start_dir):]
                except OSError, err:
                    print 'Skipping', complete_path
                except IOError, err:
                    print 'Skipping', complete_path
    
    if __name__ == '__main__':
        s = set(traverse_path('/home/hughdbrown'))
        t = set(traverse_path('/home.backup/hughdbrown'))
        for e in s - t:
            print e
        print '-' * 25
        for e in t - s:
            print e
    

    Notice that there is a check for regular files. I seem to recall that I encountered files used as semaphores or which were written to by one process and read by another or something. It turned out to be important.

    You can add code to delete files, according to whatever rules you like.

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

Sidebar

Related Questions

Can anyone please suggest a best method in PHP to make a user logs-in
can anyone please suggest a good code example of vb.net/c# code to put the
Can anyone please suggest a way to replace back-slash '\' with slash '/' in
Can anyone please suggest me a good .net code coverage plugin for Visual Studio
Can anyone please suggest me any pointer to an iterative algorithm for insertion and
Can anyone please suggest, from given date how to calculate sliding duration in javascript
Can anyone please tell me if Certifying Authorities (CAs) are allowed to make modifications
What does it mean by logical grouping of modules in assembly? Can anyone please
I want to create a box like this with title: Can any one please
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of

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.