Discussion:
[WiX-users] WiX 3.0: How to copy a directory(folder) recursively
Brian Young
2009-03-03 23:32:58 UTC
Permalink
We're using WiX version 3.0.4805.0.

We need to copy a directory recursively.

Say, there are some user data files saved in the User's 'AppDataFolder', for example, something like "C:\Documents and Settings\user_login\Application Data\CompanyName\ProductNameA". Now we need to change our proudct name from ProductNameA to ProductNameB. Then we'll need to copy the whole user data to another folder called "ProductNameB". Otherwise, the application will not recognize the user settings and data because the application can't find them. Anyways, we need to copy them to the new spot.

I know there is a way to copy a file one by one. But in our case, there is no way for us to know the user's sub-folder name and file name on the installer build time. They may even have totally different folder structure and the number of files.

Here is just an example, for user 'John', his user data maybe something like these:
AppDataFolder\CompanyName\ProductA\UserJohn\profile.xml
AppDataFolder\CompanyName\ProductA\UserJohn\ui\settings.xml
AppDataFolder\CompanyName\ProductA\UserJohn\contacts\
AppDataFolder\CompanyName\ProductA\UserJohn\media\settings.xml
AppDataFolder\CompanyName\ProductA\UserJohn\media\audio\status.xml
AppDataFolder\CompanyName\ProductA\UserJohn\media\audio\clip1.wav
AppDataFolder\CompanyName\ProductA\UserJohn\media\audio\clip2.wav
AppDataFolder\CompanyName\ProductA\UserJohn\media\video\status.xml

For user 'Alice', her data maybe something like these:
AppDataFolder\CompanyName\ProductA\UserAlice\profile.xml
AppDataFolder\CompanyName\ProductA\UserAlice\brand.xml
AppDataFolder\CompanyName\ProductA\UserAlice\history\history1.xml
AppDataFolder\CompanyName\ProductA\UserAlice\history\history2.xml

So we need a way to "just recursively copy a directory from one spot to another no matter what are inside the directory".

I tried something like these:
<Directory Id='TARGETDIR' Name='SourceDir'>
....
<Directory Id="CompanyFolder" Name="MyCompany Inc.">
<Directory Id="MySource" Name="Good Product">
</Directory>
<Directory Id="MyTarget" Name="Great Product">
</Directory>
<Component Id="CopyUserDataDir" Guid="..." >
<CopyFile Id="CopyDataDir" SourceName="*" SourceProperty="MySource" DestinationProperty="MyTarget" />
</Component>
</Directory>
</Directory>

But I quickly got some errors:
error LGHT0204: ICE18: KeyPath for Component: 'CopyUserDataDir' is Directory: 'CompanyFolder'. The Directory/Component pair must be listed in the CreateFolders table.
error LGHT0204: ICE38: Component CopyUserDataDir installs to user profile. It must use a registry key under HKCU as its KeyPath, not a file.
error LGHT0204: ICE64: The directory CompanyFolder is in the user profile but is not listed in the RemoveFile table.
error LGHT0204: ICE64: The directory MySource is in the user profile but is not listed in the RemoveFile table.
error LGHT0204: ICE64: The directory MyTarget is in the user profile but is not listed in the RemoveFile table.

Can someone provide a solution about how to do it in WiX 3.0? Some code example is welcome.

Thanks you all.

/Brian



__________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now at
http://ca.toolbar.yahoo.com.
Bob Arnson
2009-03-04 06:58:47 UTC
Permalink
Brian Young wrote:
> We need to copy a directory recursively.
>
MSI doesn't support that. You can do wildcards but not ad-hoc
subdirectories.

--
sig://boB
http://joyofsetup.com/
Brian Young
2009-03-04 18:11:18 UTC
Permalink
Thanks Bob for your reply. I appreciate it.

It's sad to learn MS doesn't support it. I'll see if I could use a CustomAction and a DLL to do the work.

Thanks again.
/Brian



__________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now at
http://ca.toolbar.yahoo.com.
Bob Arnson
2009-03-04 18:42:19 UTC
Permalink
Brian Young wrote:
> It's sad to learn MS doesn't support it. I'll see if I could use a CustomAction and a DLL to do the work.
>

If the list of directories is known, you don't need to do that. If it's
not, you can write a custom action to write rows to the MoveFile table
to do the copying. See
http://www.joyofsetup.com/2007/07/01/semi-custom-actions/ for an example.

--
sig://boB
http://joyofsetup.com/
John Nannenga
2009-03-09 23:43:23 UTC
Permalink
Quick question...should this work after the product is installed i.e., in maintenance mode or even in a patch?

A quick implementation we've messed with results in a read only session object in these situations; before we get heavy into looking into this, wanted to see if you knew off the top of your head...





________________________________________
From: Bob Arnson [***@joyofsetup.com]
Sent: Wednesday, March 04, 2009 12:42 PM
To: General discussion for Windows Installer XML toolset.
Subject: Re: [WiX-users] WiX 3.0: How to copy a directory(folder) recursively

Brian Young wrote:
> It's sad to learn MS doesn't support it. I'll see if I could use a CustomAction and a DLL to do the work.
>

If the list of directories is known, you don't need to do that. If it's
not, you can write a custom action to write rows to the MoveFile table
to do the copying. See
http://www.joyofsetup.com/2007/07/01/semi-custom-actions/ for an example.

--
sig://boB
http://joyofsetup.com/
Bob Arnson
2009-03-10 01:18:20 UTC
Permalink
John Nannenga wrote:
> Quick question...should this work after the product is installed i.e., in maintenance mode or even in a patch?
>

Yes. It's required, because during maintenance, you'll likely need to
write the same rows to get MSI to repair or remove them.

--
sig://boB
http://joyofsetup.com/
Loading...