I have a recursive directory called 'dir'. I am writing to list of files from all subdirectories to a CSV file with the following command in linux on the terminal.
dir$ find . -type f -printf '%f\n' > old_names.csv
I am using a detox code to change filenames. And I am making a new list using
dir $ find . -type f -printf '%f\n' > new_names.csv
I would like to join this to lists together and make a new list with two columns something like this;
To do that I read both csv files into pandas data frame and join them on index as follows in python3 script
import pandas as pd import csv df_old=pd.read_csv(os.path.join(somepath,'old_names.csv') df_new=pd.read_csv(os.path.join(somepath,'new_names.csv') df_names=df_new.join(df_old)
The problem is I am getting something like this, wrong file pairs;
When I open the new_names.csv I see that file list is written in a different order than old_names list so joining on index resulting in wrong pairs. How can I solve this problem?