Check if file has a parent folder

I have a situation where I have Hazel looking at an incoming folder. Sometimes I have files come in that are inside of a folder and sometimes they only come in as files without a folder.
I then run a rule that renames the file based on the parent folder. The problem is with the files that have no folder, they are getting renamed with the incoming folder name and this causes issues.
Does anyone know of a way to have a rule/script look at the parent folder of the file in question and do a check? For example:
If file has parent folder named "Incoming" then do nothing. Else, rename file to parent folder.
Thanks for any suggestions!
I then run a rule that renames the file based on the parent folder. The problem is with the files that have no folder, they are getting renamed with the incoming folder name and this causes issues.
Does anyone know of a way to have a rule/script look at the parent folder of the file in question and do a check? For example:
If file has parent folder named "Incoming" then do nothing. Else, rename file to parent folder.
Thanks for any suggestions!