<jupyter_start><jupyter_text>Renaming file names for IMDB dataset* unsup folder contains unlablled text files: X_0.txt ie. ig. 0_0.txt* neg folder contains negative text files: X_1-4 ie. 1_1.txt, 99_4.txt* pos folder contains positive text files: X_7-10 ie. 4_8.txt, 100_10.txt<jupyter_code>import os
import fnmatch
#List all text files
#'C:/Users/piyak/Github/my-project/Semi-supervised-sequence-learning-Project/imdb_review_scrapping/unsup'
directory = ('E:/00.Miscellaneous/~Macquarie University/Session 2/COMP8240 – Applications of Data Science/Research papers/New dataset/IMDB/')
unsup_path = (directory + 'unsup')
files_to_rename = fnmatch.filter(os.listdir(unsup_path), '*.txt')
#print(files_to_rename)
#Adding '_0' to all text files in unsup folder
for file in files_to_rename:
    old_name = os.path.join(unsup_path, file)
    #get file name without extension
    filename = os.path.splitext(file)[0]
    new_name = os.path.join(unsup_path, filename + '_0' + '.txt')

    # Renaming the file
    os.rename(old_name, new_name)

#Verify the result
files_to_rename = fnmatch.filter(os.listdir(unsup_path), '*.txt')
#print(files_to_rename)
#List all text files
neg_path = (directory + 'neg')
files_to_rename = fnmatch.filter(os.listdir(neg_path), '*.txt')
#print(files_to_rename)
#Adding '_' + random number between 1-4 for all text files in neg folder
import random
for file in files_to_rename:
    old_name = os.path.join(neg_path, file)
    #get file name without extension
    filename = os.path.splitext(file)[0]
    n = random.randint(1,4)
    new_name = os.path.join(neg_path, filename + '_'+ str(n) + '.txt')

    # Renaming the file
    os.rename(old_name, new_name)
#Verify the result
files_to_rename = fnmatch.filter(os.listdir(neg_path), '*.txt')
#print(files_to_rename)
#List all text files
pos_path = (directory + 'pos')
files_to_rename = fnmatch.filter(os.listdir(pos_path), '*.txt')
#print(files_to_rename)
#Adding '_' + random number between 7-10 for all text files in pos folder
import random
for file in files_to_rename:
    old_name = os.path.join(pos_path, file)
    #get file name without extension
    filename = os.path.splitext(file)[0]
    n = random.randint(7,10)
    new_name = os.path.join(pos_path, filename + '_'+ str(n) + '.txt')

    # Renaming the file
    os.rename(old_name, new_name)
#Verify the result
files_to_rename = fnmatch.filter(os.listdir(pos_path), '*.txt')
#print(files_to_rename)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12388302193338749, 'fraction_numerical': 0.017059301380991064, 'mean_word_length': 4.864285714285714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '67762', 'license': 'MIT', 'n_tokens_mistral': 907, 'n_tokens_neox': 894, 'n_words': 218, 'path': 'imdb_review_scrapping/rename_files.ipynb', 'repo_name': 'sanjay-kv/Semi-supervised-sequence-learning-Project', 'size': '2462'}