If you turn on verbose output during compilation (File > Preferences > Show verbose output during: > compilation (check)) then you can get an idea of which file is related to the problem and where that file is.
What I do in this situation is to modify my antivirus settings to whitelist the problematic file/folder/application/process. I remember someone recently saying that's no possible with McAffee antivirus but I don't use it so you might want to check and if there's no way to do this then consider using a more configurable antivirus program. Windows Defender allows you to do this so it's pretty sad if a reputable commercial software does not. It seems like there is such a strong trend lately of dumbing down user interfaces.
Many thanks Pert. I think it is that when the sketch is compiled the IDE generates temporary files. Because the file generation creates new files I can't white list the file beforehand and McAfee which I am loosing faith with only allows you to white list an existing file and not a directory/folder.
Thanks for taking the time to offer a possible solution.
I suffered from this problem when compiling for any board. For a long time, prior to re-building a sketch, I got into the habit of manually deleting the IDE session's temporary build folder that's located in the following folder:
users....\appdata\local\temp
This build folder is the one that's listed in the verbose output, saying that access is denied.
(This folder is deleted on exit from the IDE).
The problem with deleting this folder is that it increases the build time.
On some occasions, the manual delete would fail, indicating that McAfee had a file open in that folder.
Then the penny dropped, so now I temporarily turn off real-time scanning when using the Arduino IDE.
Save me loads of time when debugging, as the re-compiles are so much faster now.