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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:48:53+00:00 2026-05-16T19:48:53+00:00

I am building a python script which will be removing duplicates from my library

  • 0

I am building a python script which will be removing duplicates from my library as an exercise in python. The idea is to build a dict containing a dict ( with the data and statistic on the file / folder ) for every file in folder in the library. It currently works with a set number of subfolder. This is an example of what it gives out.

>>> Files
{'/root/dupclean/working/test': {'FilenameEncoding': {'confidence': 1.0, 'encoding': 'ascii'}, 'File': False, 'T\xc3\xa9l\xc3\xa9phone': {'FilenameEncoding': {'confidence': 0.75249999999999995, 'encoding': 'utf-8'}, 'File': False, 'Extension': 'Folder', 'LastModified': 1284064857, 'FullPath': '/root/dupclean/working/test/T\xc3\xa9l\xc3\xa9phone', 'CreationTime': 1284064857, 'LastAccessed': 1284064857, 'Best Of': {'FilenameEncoding': {'confidence': 0.75249999999999995, 'encoding': 'utf-8'}, 'File': False, 'Extension': 'Folder', 'LastModified': 1284064965, 'FullPath': '/root/dupclean/working/test/T\xc3\xa9l\xc3\xa9phone/Best Of', '10 New York Avec Toi.mp3': {'FilenameEncoding': {'confidence': 0.75249999999999995, 'encoding': 'utf-8'}, 'File': True, 'Extension': 'mp3', 'LastModified': 1284064858, 'FullPath': '/root/dupclean/working/test/T\xc3\xa9l\xc3\xa9phone/Best Of/10 New York Avec Toi.mp3', 'CreationTime': 1284064858, 'LastAccessed': 1284064858, 'Size': 2314368L}, 'CreationTime': 1284064965, 'LastAccessed': 1284064857}}}}

This is how I am producing it now:

ROOT = Settings['path']
Files = {ROOT: {'File': False, 'FilenameEncoding': chardet.detect(ROOT)},}
for fileName in os.listdir ( ROOT ):
fileStats = ROOT + '/' + fileName
    if os.path.isdir ( fileStats ):
        Files[ROOT][fileName] = Analyse(fileStats)
        for fileName2 in os.listdir ( ROOT + '/' + fileName): 
            dbg(70, "Scanning " + ROOT + '/' + fileName + '/' + fileName2)
            fileStats2 = ROOT + '/' + fileName + '/' + fileName2
            #third level
            if os.path.isdir ( fileStats2 ):
                Files[ROOT][fileName][fileName2] = Analyse(fileStats2)
                for fileName3 in os.listdir ( ROOT + '/' + fileName + '/' + fileName2): 
                    dbg(70, "Scanning " + ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3)
                    fileStats3 = ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3
                    #Fourth level
                    if os.path.isdir ( fileStats3 ):
                        Files[ROOT][fileName][fileName2][fileName3] = Analyse(fileStats3)
                        for fileName4 in os.listdir ( ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3): 
                            dbg(70, "Scanning " + ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3 + '/' + fileName4)
                            fileStats4 = ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3 + '/' + fileName4
                            #Fifth level
                            if os.path.isdir ( fileStats4 ):
                                Files[ROOT][fileName][fileName2][fileName3][fileName4] = Analyse(fileStats4)
                                for fileName5 in os.listdir ( ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3 + '/' + fileName4): 
                                    dbg(70, "Scanning " + ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3 + '/' + fileName4 + '/' + fileName5)
                                    fileStats5 = ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3 + '/' + fileName4 + '/' + fileName5
                                    #Sicth level
                                    if os.path.isdir ( fileStats5 ):
                                        Files[ROOT][fileName][fileName2][fileName3][fileName4][fileName5] = Analyse(fileStats5)
                                        dbg(10, "There was still a folder left in "+ROOT + '/' + fileName + '/' + fileName2 + '/' + fileName3 + '/' + fileName4)
                                    else:
                                        Files[ROOT][fileName][fileName2][fileName3][fileName4][fileName5] = Analyse(fileStats5)
                            else:
                                Files[ROOT][fileName][fileName2][fileName3][fileName4] = Analyse(fileStats4)
                    else:
                        Files[ROOT][fileName][fileName2][fileName3] = Analyse(fileStats3)
            else:
                Files[ROOT][fileName][fileName2] = Analyse(fileStats2)
    else:
        Files[ROOT][fileName] = Analyse(fileStats)

This is obviously wrong, but for the life of me, I just can’t figure out a way to do it recursively !
Any help or pointers would be greatly apreciated.

  • 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-16T19:48:54+00:00Added an answer on May 16, 2026 at 7:48 pm

    Use os.walk.

    import os
    for dirpath,dirs,files in os.walk(ROOT):
        for f in dirs + files:
            fn = os.path.join(dirpath, f)
            FILES[fn] = Analyse(fn)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a Python script to automate my build process, which invokes GCC using
I'm building a python app where a client side will request xml pages from
I tried to build an executable for a python script using scons, which is
I'm currently building a program in C# which will call functions in provided python
So, I'm building a GUI in Python using Tkinter which will be used to,
I am trying to create a Python script which will take an address as
I am essentially building a timer. I have a python script that monitors for
I'm interested in building a python script that can give me stats on how
I am building a simple python CGI script to work with Twilio. Right now,
I'm building a python application from some source code I've found Here I've managed

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.