[LINUX] Python program that looks for the same file name

Search for files with the same name in the folder (directory) hierarchy

If the number of folders and the hierarchy are large, files are inadvertently duplicated, and similar and non-similar files remain in the hierarchy, which tends to cause problems when searching or editing.

Actually, when I took a text file that had been used for a while to a notebook app that can manage the hierarchy mechanically with a tool to mechanically migrate it to another notebook app, it seemed that there were multiple files with the same name. At this time, I wrote a program to create a file list to make it easier to find the file with the same name in order to clean it up.

Program specifications

Such a place. You can also output a complete list (listed in order of file name) and visually determine which ones are marked and which are unmarked but have similar names. I did. (If you don't like it, just look at the marked ones)

List making program (Python)

The list is created by separating the file name and folder name with ":". Arrange in ascending order of file names. If there is the same file name (before the extension), add "\ ***** duplicated file ?? ****" at the end. The folder to be searched is searched with the current folder as the top level. The file name of the output list is "out.txt", and the UTF-8 line break is only LF, so please modify it according to your environment.

I'm still new to Python, so I made it by combining information from various websites. Your opinions and professors are welcome.

ListDupFile.py


#!/usr/bin/python
# -*- coding: utf-8 -*-

import codecs
import os

oList = []
odata = ""
prev = "...."

for root, dirs, files in os.walk(u'.'):
	for file_ in files:
		filename = file_
		itm = filename + u' : ' + root
		oList.append(itm)
oList.sort()
for data_ in oList:
	wList = data_.split('.')
	if prev in wList[0] :
		data_ = data_ + "  ***** duplicated file?? ****"
	prev = wList[0]
	odata = odata + data_ + "\n"
fout = codecs.open(u'out.txt',"w","utf-8")
fout.write(odata)
fout.close()

Recommended Posts

Python program that looks for the same file name
A program that searches for the same image
Set the process name of the Python program
[Python] A program that rounds the score
[Python] I tried substituting the function name for the function name
I tried searching for files under the folder with Python by file name
[Python] A program that counts the number of valleys
[Python] A program that compares the positions of kangaroos.
Download the file in Python
[python] Change the image file name to a serial number
Miscellaneous notes that I tried using python for the matter
[Python] A program that finds the most common bird types
Google search for the last line of the file in Python
Try to decipher the garbled attachment file name with Python
Extract the xz file with python
Save the binary file in Python
Workaround for the problem that sys.argv is not passed when executing a Python script with only the file name in Python2.7 on Windows
Understand the probabilities and statistics that can be used for progress management with a python program
[Ev3dev] Create a program that captures the LCD (screen) using python
Read a file in Python with a relative path from the program
Extract the targz file using python
Python vba to create a date string for creating a file name
See python for the first time
Notes for Python file input / output
What is the python underscore (_) for?
python note: map -do the same for each element of the list
Get the host name in Python
[Python] A program that rotates the contents of the list to the left
Command for the current directory Python
[Python] A program that calculates the number of socks to be paired
If you are told cannot by Python import, review the file name
The file name was bad in Python and I was addicted to import
Find out the name of the method that called it from the method that is python
I made a program to check the size of a file in Python
Python / numpy> Read the data file with the item name line> Use genfromtxt ()
Introducing the BOT framework Minette for Python
Check the existence of the file with python
Python Master RTA for the time being
Python3 + pyperclip that rewrites the copied text
Launch the Discord Python bot for 24 hours.
Let's read the RINEX file with Python ①
Read the file line by line in Python
Read the file line by line in Python
MongoDB for the first time in Python
[python] Permutation generation considering the same elements
Pandas of the beginner, by the beginner, for the beginner [Python]
Effective Python was, as the name implies, Effective
Hashing algorithm for determining the same image
[Python] Get the character code of the file
A program that plays rock-paper-scissors using Python
[Python] Read the specified line in the file
Overwrite download file for python selenium Chrome
Python open and io.open are the same
[Python3] Understand the basics of file operations
[Python] I created an app that automatically downloads the audio file of each word used for the English study app.
python I don't know how to get the printer name that I usually use.
Are Php / Ruby / Python that only runs when the file is called directly
Python / subprocess> Symbolic link Implementation to get only the destination file name> os.readlink ()
A python script that draws a band diagram from the VASP output file EIGENVAL
[Python] A program that finds the minimum and maximum values without using methods
[Python] A program that calculates the difference between the total numbers on the diagonal line.