Как мне переименовать файл, сохранив файл в том же каталоге?
У меня есть строка, содержащая полный путь к файлу, и строка, содержащая новое имя файла (и никакой путь), например:
NSString *old_filepath = @"/Volumes/blah/myfilewithrubbishname.avi";
NSString *new_filename = @"My Correctly Named File.avi";
Я знаю о NSFileManager movePath:toPath:handler:, но я не могу тренироваться, как построить новый путь к файлу.
В основном я ищу эквивалент следующего кода Python:
>>> import os
>>> old_filepath = "/Volumes/blah/myfilewithrubbishname.avi"
>>> new_filename = "My Correctly Named File.avi"
>>> dirname = os.path.split(old_filepath)[0]
>>> new_filepath = os.path.join(dirname, new_filename)
>>> print new_filepath
/Volumes/blah/My Correctly Named File.avi
>>> os.rename(old_filepath, new_filepath)