KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How would I rename a file, keeping the file in the same directory? I have a string containing a full path to a file, and a string containing a the new filename (and no path), for example: NSString *old_filepath = @"/Volumes/blah/myfilewithrubbishname.avi"; NSString *new_filename = @"My Correctly Named File.avi"; I know about NSFileManager's movePath:toPath:handler: method, but I cannot workout how to construct the new file's path.. Basically I'm looking for the equivalent to the following Python code: >>> 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)
Tags (comma-separated)
Save Edits
Cancel