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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:54:28+00:00 2026-05-23T22:54:28+00:00

I am working on very large file system. My task is to clean the

  • 0

I am working on very large file system. My task is to clean the system with some given parameters. Below program fragment can give a idea.

import DirectoryWalker


extentions_to_delete = list([".rar",".doc",".URL",".js",".EXE",".mht",".css",".txt", ".cache", ".xml"])
extentions_to_copy = list([".jpg",".BMP",".GIF",".jpeg",".gif",".bmp",".png",".JPG"])

dw = DirectoryWalker.DirectoryWalker("/media/08247451247443AA/home/crap/")

def copy_advice(key, files):
    for ext in extentions_to_copy:
        if(ext == key):
            print str(len(files)) + " Files of type " + key + " should be coppied to the target folder."
            for file in files:
                copy_to = "/media/08247451247443AA/home/crap-pics/"

                moved = dw.move_file_to(file, copy_to, True)
                if not moved:
                    print file + " : not moved"

walks = dw.get_all_file_types()


for key in DirectoryWalker.Walk.store.keys():
    files = DirectoryWalker.Walk.store[key]

    copy_advice(key, files)

In the DirectoryWalker following code is written. Walk is a simple class which have a store object.

def get_all_file_types(self):

    extentions = []

    for dirpath,dirnames,filenames in os.walk(self.dir_name):
        for file in filenames:
            extentions.append(Walk(dirpath +"/"+ file))

    return extentions            

def move_file_to(self, file_path, copy_to, rename_if_exists= False):
        file_name = os.path.split(file_path)[1]

        target_file_name = copy_to + file_name;

        coppied = False

        if not os.path.isfile(target_file_name):
            coppied = True
            try:
                os.rename(file_path, target_file_name)
            except OSError:
                coppied = False
                print "Oops! Unable to rename : " + file_path + " to target : " + target_file_name

        if rename_if_exists:
            coppied = True
            file_name = "new_"+ file_name
            try:
                os.rename(file_path, target_file_name)  
            except OSError:
                coppied = False
                print "Oops! Unable to rename : " + file_path + " to target : " + target_file_name        

        return coppied

The Walk class

class Walk:

    store = dict([])

    def __init__(self, filename):

        self.file_ext = os.path.splitext(filename)[-1]
        self.file_name = filename

        if not (Walk.store.has_key(self.file_ext)):
            Walk.store[self.file_ext] = list() 

        Walk.store[self.file_ext].append(self.file_name)

But when program executed, it only moves almost 10400 files. But manual calculation suggest, there should be 13400 files in the file system. Please let me know, what I am doing wrong?

Update Solutions

After a careful investigations, I come out with result that there are many ambiguous file names in the target file system and those files were missing.

  • 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-23T22:54:30+00:00Added an answer on May 23, 2026 at 10:54 pm

    After a careful investigations, I come out with result that there are many ambiguous file names in the target file system and those files were missing.

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

Sidebar

Related Questions

I am working with a very large (~11GB) text file on a Linux system.
We're working with some very large config files which contain lots of Unity and
I'm working on a program to factor very large numbers (20 digits or more)
I am working with a very large text file (500MB+) and the code I
I have a program that is very heavily hitting the file system, reading and
I am working on a C# program that produces a very large piece of
I am working on a C# program that reads in very large files and
When working with very large documents, would it basically overwhelm the connection and ground
I'm working on a very large project that has associated class files in multiple
I'm working on a very large project with three phases of source code. Development

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.