Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from glob import glob
- from os import rename, listdir
- # Makes a .csv file with a row of file names per subdirectory
- # Appends "directoryName_" to each file
- # Get the audio directory path
- path = os.path.dirname(os.path.realpath(__file__))
- folderName = os.path.basename(path)
- csvFile = open('fileNamesPerDirectory.csv', 'w')
- for root, directories, meh in os.walk(path):
- for directory in directories:
- files = listdir(os.path.join(path, directory))
- namesNoExtension = []
- for name in files:
- namesNoExtension.append(name.replace('.wav', ''))
- # Write a row with file names per directory (to the CSV file)
- commaSeparatedString = ','.join(map(str, namesNoExtension))
- csvFile.write(directory + ',' + commaSeparatedString + '\n')
- for file in files:
- if file.endswith('.wav'):
- pathToFile = os.path.join(root, directory, file)
- newName = directory + '_' + file
- newPath = os.path.join(root, directory, newName)
- rename(pathToFile, newPath)
- csvFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement