I am using the os.replace
function to rename a folder. The folder will remain in the same parent directory.
parent_dir = '/Users/my_Username/Desktop/'
old_name = 'foo'
new_name = 'bar'
os.replace(parent_dir + old_name, parent_dir + new_name)
This code works, but feels a little redundant, especially when using long variable names and when calling this function multiple times.
According to the docs,
This function can support specifying src_dir_fd and/or dst_dir_fd to supply paths relative to directory descriptors.
However, I cannot figure out how to pass in the relative path of both folders. I thought it would be something like this:
os.rename(old_name, new_name, src_dir_fd=parent_dir)
But that doesn't work.
How do I pass in a relative path?