I am trying to rename multiple files by importing the OS Module (Mac OS). To do this I have first split the files' titles from their extension and then the files (pdfs in this case) had an additional format specification (a4). Here's an example : "darwinism_a4.pdf". I am trying to remove the "a4" part. So, I have tried split the name at the underscore using this line : f_title, f_format = f_name.split(""). At this point I have received this error message :
Traceback (most recent call last): File "/Users/me/Documents/Programming/Cody_schafer/training.py", line 10, in f_title, f_format = f_name.split("_") ValueError: not enough values to unpack (expected 2, got 1)
I have finished the code anyways to show what I want to achieve and will include it here.
import os
for f in os.listdir():
f_name, f_ext = os.path.splitext(f)
print(f_name.split("_"))
f_title, f_format = f_name.split("_")
print(f_title, f_format)
new_name = '{}-{}'.format(f_title, f_ext)
os.rename(f, new_name)
I am thinking maybe it has something to do with all the files not having the same format? There's a file titled '.DS_Store' (for desktop services). It's put there by default.