Lewis
Lewis

Reputation: 159

Rename multiple files in a directory in objective-c

I need to remove the first 4 characters of the names of over 100 files in a certain directory, can I do this with an obj-c program or a c ++ program and if so how?

Upvotes: 0

Views: 645

Answers (1)

nikora
nikora

Reputation: 817

Yes you can.

The NSFileManager class provides all the methods you need.

To get the contents of the directory use the contentsOfDirectoryAtPath method. To rename the file you need to use the moveItemAtPath method.

Take a look at the class reference https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

Steps: 1. Get the names of the files in the dir. 2. Iterate all the files and use the moveItemAtPath to rename.

Upvotes: 2

Related Questions