def check_if_all_files_of_same_size(folder_path, file_name_list, one_but_last):
    '''
    Checking if iles are of the same size. It is useful for check if the data files
    in the folder are from one continous observation, or there were stops of recording.
    The check for this purpose a list of all but last file should be analyzed
    one_but_last = 0 - Analyze all files
    one_but_last = 1 - Analyze all but last file
    '''
    if len(file_name_list) > 1:
        filesize = np.zeros(len(file_name_list) - one_but_last)
        filesize_text = [''] * (len(file_name_list) - one_but_last)
        for i in range(len(file_name_list) - one_but_last):
            filepath = folder_path + file_name_list[i]
            filesize[i] = (os.stat(filepath).st_size)
            filesize_text[i] = str(filesize[i])

        unique = find_unique_strings_in_list(filesize_text)


    if len(file_name_list) == 1 or len(unique) == 1:
        equal_or_not = 1
        print('   OK: all files have the same size!')
    else:
        equal_or_not = 0
        print('\n **********************************************************\n !!!      WARNING: Sizes of files in folder differ      !!! \n **********************************************************')
        print('\n   * Check the size of each file in list: \n')
        print('   No       Size in bits       File name \n')
        for file_no in range (len(file_name_list) - one_but_last):
            print('  {:0>4d}'.format(file_no+1), '   {:15.0f}     '.format(filesize[file_no]), file_name_list[file_no])
        print('  * Last file was not taken into account!')

    return equal_or_not
Ejemplo n.º 2
0
#      *** Making a list of folders with ADR files ***

# Search needed files in the directory and subdirectories
file_path_list, file_name_list = find_all_files_in_folder_and_subfolders(
    path_to_data, '.adr', 0)

# Making all slashes in paths of the same type
for i in range(len(file_path_list)):
    file_path_list[i] = file_path_list[i].replace('\\', '/')

# Taking only paths without
for i in range(len(file_path_list)):
    file_path_list[i] = file_path_list[i][:-len(file_name_list[i])]

list_of_folder_names = find_unique_strings_in_list(file_path_list)

print('\n  Number of ADR files found: ', len(file_name_list))
print('\n  List of folders to be analyzed: \n')
for i in range(len(list_of_folder_names)):
    print('         ', i + 1, ') ', list_of_folder_names[i])

# Take only one folder, find all files
num_of_folders = len(list_of_folder_names)
same_or_not = np.zeros(num_of_folders)
equal_or_not = np.zeros(num_of_folders)
for folder_no in range(num_of_folders):
    file_name_list_current = find_files_only_in_current_folder(
        list_of_folder_names[folder_no], '.adr', 0)
    print('\n\n\n\n * Folder ', folder_no + 1, ' of ', num_of_folders,
          ', path: ', list_of_folder_names[folder_no],