同じディレクトリにファイルを保持したまま、ファイルの名前を変更するにはどうすればよいですか?
ファイルへのフルパスを含む文字列と、新しいファイル名を含む(パスなしの)文字列があります。次に例を示します。
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)