It is not good idea compare project item NAME and file relative PATH.
For example, relative path may equals "\Foo\Bar\Class.cs", but name is "Class.cs".
You can use following code:
            ProjectItem projectItem = null;
            foreach (var part in filePath.Split('\\'))
            {
                var items = projectItem != null ? projectItem.ProjectItems : project.ProjectItems;
                projectItem = items.Cast<ProjectItem>().FirstOrDefault(item => item.Name.Equals(part, StringComparison.InvariantCultureIgnoreCase));
                if (projectItem == null)
                    break;
            }
            return projectItem;