How to get data from 100 txt files in a folder, and put it in a single file(need file name as a column)? : I have a folder with 80 txt files and their names are years they were created(example 2008P1,2008P2 2009 P1 etc). Each file has a single column of data with more than 100000 rows. I want to put all these data in a single file in a sequence of their name(year wise).

The sequence would be the year they were created, oldest first, latest last.

Also I need an additional column in new file with the name of the file they were taken from.

Need to do this with Python or R.. Please help.

files:

2008
2008P1
2008p2
2009P1
2009p3
.
.
.
.
.
2019P3


Data in file:
$h|fffff|P|....
$C|fffff|P|....
.
.
.
.
.