
:max_bytes(150000):strip_icc()/006-using-automator-to-rename-files-and-folders-32ab9dd6b8c24aacbd1d3bb56cc27ae1.jpg)
Let’s break down what we’ve done here bit by bit. Since we can access so many different elements of a Pathlib object, we can use these elements to organize our files into meaningful folders. If you want to also organize your files into folders for each of the months, read on. It will make the changes right away (and Mac OS and Windows don’t let you to just hit “undo” - so be careful!). If you’re content with just renaming the files, feel free to run your code now. Phew! Ok, awesome! You’ve made it this far.
:max_bytes(150000):strip_icc()/005-using-automator-to-rename-files-and-folders-25a20ed650ea4358ba1f43c4a648a2df.jpg)
rename() method on the file itself, passing in a concatenation of the directory and the new name. (if you were to print out a new_name, it’d look like this: /Users/nikpi/Desktop/Files/2021–01–01 - East - Sales.xlsx) Finally, we create a new_name variable that uses f-strings to concatenate our other strings into a single filename.Because we want to change the date format, we turn the date string into a datetime object and then back into a string with our desired output format.stem attribute) into meaningful names (region, report_type, and old_date) We unpack our old file name (created using the.

