8

I have just started making a test app , here is what happened.

  1. I copied some files in to my project.

  2. deleted them, as reference only.

  3. I tried to add them again,

and i get the following error

" randomfile.h couldn't be copied to TestApp because an item with same name already exists "

randomfile.h is the file i am trying to add and TestApp is the project name.

How can i add the same file again?

4 Answers 4

28

Un-select the "Copy items into destination if needed" checkbox. Are you adding the file from and to the same folder? If it's from a different folder, then you need to rename or delete the one that you had before.

2
  • It worked, but i don't understand the problem i was facing or the reason, can you explain in detail? Nov 17, 2011 at 19:19
  • Sometimes it could be so easy! Thanx Matt! Apr 23, 2012 at 8:39
10

It worked, but i don't understand why this happened, can you explain in detail?

You deleted the items by reference only, that means that you only deleted the projects reference to it, essentially, removing it from the project, but not deleting it from disk. So the file is still on your hard drive in your project files directory. Trying to copy another instance of it will be like trying to copy 2 files with the same name into the same directory, thus you get the "because an item with same name already exists" error

0
2

However, this doesn't work if you delete folders. Here are steps to reproduce:

Add a folder called "images".

In that folder, add a folder called "test".

Put a couple of files in the test folder.

Delete the test folder. Select "move to trash" (as opposed to delete references).

Try to add a "test" folder into the images folder by dragging in from finder.

Error by OP appears - xcode does not delete folders (or subfolders) when you select the move to trash option, even when you have that folder selected. You have to manually remove the folders from finder.

1
  • Even after deleting the folders in Finder I get the same message...way to go Xcode. Restarting my mac completely was the only thing that fixed it. Sep 9, 2014 at 8:46
1

Go to project directory to find and delete the file that has the same name as the one you were trying to copy to project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.