Q:

Wix - how to prevent overwrite entire directory?

I have wix installer and it copies some files to some directories. Each file is declared as single component, with some path - if directory does not exist, installer will create it and place file there.
What I want to do: if directory already exists, installer should not copy any files there (even if file does not exists, it should not be copied to already existing directory). 
But it's impossible to set "Never overwrite" to directory, so how can I prevent copy new files to already existing directory? Is there any condition (something like "is directory exist") that I can use here?

A:

Is there any condition (something like "is directory exist") that I can use here?

Yes, you can use a Condition element like this:
<Directory Id="FooFolder" Name="Foo">
    <Component Id="SomeId">
        <File Source="..." />
        <Condition>Not FOO_FOLDER_ALREADY_EXISTS</Condition>
    </Component>
</Directory>

The kind of things that you can use as a condition are explained in the Conditional Statement Syntax documentation of windows installer.
In this case, I believe you can set the FOO_FOLDER_ALREADY_EXISTS property with a DirectorySearch like this:
<Property Id="FOO_FOLDER_ALREADY_EXISTS">
    <DirectorySearch Id="FooFolderSearch" Path="[FooFolder]" />
</Property>

edit: apparently the directory search above doesn't work because the [FooFolder] property is only resolved during the CostFinalize action (see documentation). But the directory search already happens before that during the AppSearch action.
I am unsure how to work around that. It would probably involve setting the FOO_FOLDER_ALREADY_EXISTS property after CostFinalize with a custom action instead of a windows installer directory search.

