How to omit specific directories, while logging code

I am trying to log code using the following command:
wandb.run.log_code(".")

However, this captures all the folders and files in the current directory. I also came across this command:
wandb.run.log_code(".", include_fn=lambda path: path.endswith(".py"))

My issue is that I need to log .py files along with certain folders, but exclude some specific folders. Is there a way to achieve this?