Skip to content
Advertisement

Linux command from python to execute inside subfolders

This is my folder structure:

JavaScript

As their are many csv files inside a particular date. i want to combine all csv file inside each date folder with header of 1st file only into one single file and name is as orderno_year_month_date.csv. means every datefolder will have have only one csv named after their parent folders.So, i want clean command for this in linux which i can run outside of ORDERNO directory or execute same command using python script such that i don’t have to go again and again inside folder and manually execute the command.

**This same question is posted in askubuntu 3 months before but no answers there.

Expected structure should be like

JavaScript

Previously i was going to each date folders of each month folder of each year folder of each order no. and use to run this command for single file for header.

JavaScript

Advertisement

Answer

I will be using this mock file structure (plotted using the tree command, and saved under ~/test/ in my computer):

JavaScript

You can rename the files using Python, with the help of pathlib and concatenate them using pandas:

JavaScript

This yields:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement