Enabling a contributed module under certain path only
Well yes you can ... but you shouldn't you may want to think of the code quality of the custom module, because it should only be responsible for the exact functionality you require. 

I say you can because yes:

//Enable.
$modules = ['custom_scarry_module'];
module_enable($modules, TRUE);

// Disable.
if (module_exists('custom_scarry_module')) {
  module_disable(['custom_scarry_module']);
}


But again perhaps rethink the "why" aka what Jaypan said.