How to rename the folder name in xcode project with out corrupting the files

Go To


In my xcode project i have created a folder manually named "MyClasses" to place the newly added files/classes to this folder.

Now i have nearly 30 classes in this folder.

when i renamed this folder , all the files in this folder are gets Erased.

Now i need to rename the folder to "ViewControllerClasses".

But i lost 30 .h, .m, xib files. [lucky i have a copy & and zip file]

How to rename the folder with out corrupting the files.

enter image description here

enter image description here

Renamed it to myviewcontrollerclasswes

When i renamed

enter image description here enter image description here

2012-04-04 07:12
by Ranga
Do u want to rename the folder in xcode only or both in xcode & the place where it resides in your harddisk (shown by finder - hp iOS Coder 2012-04-04 07:17
i want to rename the the place where it resides in shown by finde - Ranga 2012-04-04 07:21
@Ranga Did you close the X-code before renaming the folder - Bazinga 2012-04-04 08:41
Yes i did. After close my xcode then i renamed the folder's nam - Ranga 2012-04-04 08:50
THIS IS NOW AUTOMATED IN XCODE .. - Fattie 2013-12-06 09:35


NOTE as of 2017: Now Xcode 9 synchronises the folder and the project hierarchy automatically.

NOTE as of 2013: Duplicate and rename Xcode project & associated folders

The "folders" what you see in XCode under your project file are not real folders in the file system, only virtual folders administered in the .xcodeproj file. You can organize your files in the project folder independently from their location in the file system. Some prefers to map the file system folder structure inside the project folder structure, some others store all source files in one big folder in the file system and organize them only in the project folders: it's rather a question of preference.

However if you rename/move physically the files in the file system, you will have to delete and re-add them to your project since XCode will not know where to find them. Pay attention not to delete them physically only remove them from XCode project, then re-add them and reorganize as you want.

One more thing to note: if you are using version control system you will have to inform also its client (svn or git most likely) that you have renamed/moved your files. If you want to keep file revision history it will be a good idea to issue the copy/move command explicitly to the version control otherwise it will treat your files as deleted from the old location and added as new in the new location.

2012-04-04 09:40
by MrTJ
+1 for the hint about version control! Regarding delete and re-add of the group after physically renaming the folder in the file system: I'm not sure about other versions, but in Xcode 4.2 this is not necessary. You can select the group in Xcode, display the File Inspector (keyboard shortcut Option+Command+1), then in the File Inspector window click the small button below the "Path" combo box. This will pop up a file dialog where you can choose the folder that the group represents - herzbube 2012-06-09 17:43
Nice, I did not know about this. I was not completely exact in the answer above since it is also possible to create groups in project folder that maps directly a folder in the file system and their contents will be synchronized automatically. They have blue folder icon in XCode if I remember well. However they are mostly used for resources only - MrTJ 2012-06-11 06:56
You would have thought 4.6.2 versions in Apple will have sorted out this disgraceful syste - Adam Waite 2013-06-04 15:14
This is not any more 100% correct. Now xcode 9 can create folder with real folders in the file system - Stephan 2017-12-26 16:15
Thanks @Stephan, I added an updated to the old answer - MrTJ 2018-01-02 10:54


Two Solutions

Method_1. Try Manual editing:

  « Drag your MedChart.xcodeproj to TextWrangler  (or any text editor) 

  « Use find button to find "FolderName" (Your folder name) 

  « Replace all with new name.

  « In some project you may notice header search path problem...goto header search path and replace with new name.

Method_2. Use Xcode to choose base folder:

Rename folder in finder then use Xcode to choose same folder. enter image description here

2013-09-24 04:52
by Guru
if use git , how to save the file git status history - iHTCboy 2017-05-26 01:42


In case anyone is still having trouble with this:

  1. Select the folder or file in the left-side bar of XCode corresponding to the folder you want to rename (for me I renamed the folder containing all my files so I selected the topmost folder)
  2. On the right-side bar, below where it says 'Location', click the folder icon.
  3. In the file explorer that opens up rename the existing folder to whatever name you'd like it to be, then afterwards select it and press 'Ok'.
  4. XCode should update the file locations accordingly.

Keep in mind that if you rename something which contains a file that is hard-coded as a certain path in your build settings, XCode will throw an error. You'll have to manually change those paths in your build settings.

This worked for me, hope it works for you too.

2016-06-14 20:21
by Shady
This is a much better answer than the accepted one. You do not have to remove and add all the files manually. Be sure to update the path to the info.plist however - picciano 2016-06-23 13:02
This doesn't seem to work on image assets or Pod - Brian Ogden 2017-06-10 20:56


You should just run a search and replace on the project file (if you are working with version control and with other developers you will have seen this file a lot without a doubt), it's the project.pbxproj file located inside the xxxxxxxx.xcodeproj file.

Just right click (Control + Click) on the file and select "Show Package Contents" to find the xcodeproj file.

2013-05-08 21:54
by Daniel
Dan - fantastic awesome tip, thanks for that. I believe the file may actually be today "UserInterfaceState.xcuserstate" .. I edited in some long instructions for any future readers. thanks again man, merry xmas - Fattie 2013-12-06 09:29