Generally, if you want to call some function on opening a buffer from some specific directory, then you can use .dir-locals.el, e.g. you could use the following definitions:
((nil . ((eval (lambda () (load-theme 'zenburn t))) (eval (lambda () (add-hook 'kill-buffer-hook (lambda () (disable-theme 'zenburn)) nil t))))))
However, this switches the theme only on creating or killing the buffer.
Therefore, to make it load/disable a theme on switching to/from the buffer you could use the following (hook-)function:
(defun conditionally-switch-theme () (when buffer-file-name (if (string= (file-name-directory buffer-file-name) "/your/directory/path") (load-theme 'zenburn t) (disable-theme 'zenburn)))) (add-hook 'window-configuration-change-hook #'conditionally-switch-theme)
Finally, loading a theme does not disable the currently enabled themes. But as that is often not really necessary, I did not bother to sort it out. But if some things are not working as expected, then add some logic to remember the current custom-enabled-themes, disable them before loading the 'local' theme on entering the buffer, and enable the themes in the stored value of the previous custom-enabled-themes after disabling the 'local' theme when leaving the buffer (see also Custom themes in the Emacs manual).