I have two folders with the same file names, but when I try to read all text files from the folders in python, it reads in a different order. but I need to read files from two folders in the same order because they correspond. I used the following code to read all text files in a folder.
 dir_psnr=current_path+'\\'+dir_psnr+'\\'
os.chdir(dir_psnr) #change directory to downloads folder
files_path =[os.path.abspath(x) for x in os.listdir()]
fnames_psnr_tmp = [x for x in files_path if x.endswith(".txt")]
the address of the folders are as follows:
F:\RD_data_from_twitch_system\RD_data_from_twitch_system\psnr
F:\RD_data_from_twitch_system\RD_data_from_twitch_system\bitrate
the name of text files in both two folders are as follows:
asmr_1.txt
asmr_2.txt
Counter_strike_1.txt
Counter_strike_2.txt
dota2_1.txt
what is the problem? and how can I read files in the same order? the full code is :
def reading_file_to_array(dir_psnr,current_path):
    dir_psnr=current_path+'\\'+dir_psnr+'\\'
    os.chdir(dir_psnr) #change directory to downloads folder
    files_path =[os.path.abspath(x) for x in os.listdir()]
    fnames_psnr_tmp = [x for x in files_path if x.endswith(".txt")]
   .
   .
   .         
    return()
current_path='F:/RD_data_from_twitch_system/RD_data_from_twitch_system'
current_dir ='F:/RD_data_from_twitch_system/RD_data_from_twitch_system'
all_sub_dir_paths = glob(str(current_dir) + '/*/') 
all_sub_dir_names = [Path(sub_dir).name for sub_dir in all_sub_dir_paths] 
    for i in range(len(all_sub_dir_names)):
    if all_sub_dir_names[i]=='bitrate':
        bitrate_1080p,bitrate_720p,bitrate_480p,bitrate_360p,bitrate_160p=reading_file_to_array(all_sub_dir_names[i], current_path)
    else:
        psnr_1080p,psnr_720p,psnr_480p,psnr_360p,psnr_160p=reading_file_to_array(all_sub_dir_names[i], current_path)