Is it possible to prevent creation of .directory files?
Solution 1:
Dolphin uses those files to remember the view properties of each folder. You can easily get rid of them by choosing common view properties for all folders
in Dolphin preference under general
tab. But, obviously, there won't be specific properties for specific directories anymore.
Solution 2:
As far as I have experienced, you can not prevent specific .directory-files from being created - unless you tweak some options for your entire KDE-profile. .directory-files store options specific to each folder. If you make dolphin use the same view-settings for all folders, you can prevent a lot of those files from being created in the first place. I also suggest turning off all sorts of previews for files within dolphin.
If the compiler can handle empty files, what about just creating an empty .directory-file and revoking write-privileges?
touch .directory; chmod 444 .directory