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?
find
s must produce output in the same order, so the whole exercise may be flawed, but if you're in a situation where they do, do you need to be using Python to join them or wouldpaste
suffice? – Michael Homer Jan 21 '19 at 19:11detox
will tell you what changes it's making and you'd be better off to use that information instead, I think, rather than trying to reverse-engineer it. – Michael Homer Jan 21 '19 at 19:18