Some editor code help

Ran into a bit of a snag

I’m trying to get the prefab of the gameObject I currently have selected and then also the path of the prefab.
target is my selection
Im editing a script that another guy made.

This does give me the name of the gameObject I have selected.

(Component)target).gameObject.name
UnityEngine.Object GameObject2 = PrefabUtility.GetCorrespondingObjectFromSource(PrefabUtility.GetPrefabInstanceHandle((Component)target));
                                string prefabPath = AssetDatabase.GetAssetPath(GameObject2);
                                Debug.Log("Path: " + prefabPath);

Nevermind finally figured it out.
took a while trying out different methods.

I just had to do this

string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot((Component)target);
                                Debug.Log("Path: " + prefabPath);