Renaming Files

Renaming Every File in a Folder

Python 3

import os
path = 'C:\\Users\\Justin\\Desktop\\test folder\\file-folder'
files = os.listdir(path)
for file in files:
    os.rename(os.path.join(path, file), os.path.join(path, 'xyz_' + file + '.txt'))

import os
path = 'C:\\Users\\Justin\\Desktop\\test folder\\file-folder'
files = os.listdir(path)
counter = 0
for file in files:
    os.rename(os.path.join(path, file), os.path.join(path, 'xyz_' + str(counter) + '.txt'))
    counter += 1

import os
path = 'C:\\Users\\Justin\\Desktop\\test folder\\file-folder-2'
files = os.listdir(path)
for file in files:
    stringVar = ''
    digitList = list(filter(str.isdigit, file))
    for digit in digitList:
        stringVar = stringVar + digit
    os.rename(os.path.join(path, file), os.path.join(path, 'xyz_' + stringVar + '.csv'))