Dynamicly adding files and folders

May 27, 2015 at 2:15 PM
Hi,

First of all nice work!

In my case my msi contains 2 parts,
Part 1: is generated from VS and is static so coding this part was easy.
Part 2: This is generated from external tools and sources and is dynamic meaning the the code i a writing should scan files and folders and add them automaticly to the MSI. and there is a catch

There are files in different folders with the same name.

Any help is welcome even tips or ... because for the moment i am goiing crazy in trying different steps ...
Dir RootFolder = new Dir(_InstallDir);
System.IO.FileInfo[] files = null;
System.IO.DirectoryInfo[] subDirs = null;
if (files != null)
{
foreach (System.IO.FileInfo fi in files)
{
RootFolder.AddFile(new File(GenerateRandomID(), fi.FullName));
}
}
subDirs = rootfolder.GetDirectories();
foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
RootFolder.AddDir (ScanSubFolder(dirInfo));
}
_MSIFile.AddDir(RootFolder);

        private Dir ScanSubFolder(System.IO.DirectoryInfo sourceFolder)
        {
            Dir WixDir = new Dir(sourceFolder.Name);
            System.IO.DirectoryInfo[] subdirs = null;
            System.IO.FileInfo[] files = null;

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    WixDir.AddFile(new File(fi.FullName));
                }
            }

            subdirs = sourceFolder.GetDirectories();

            foreach (System.IO.DirectoryInfo dirInfo in subdirs)
            {
                WixDir.AddDir(ScanSubFolder(dirInfo));
            }

            return WixDir;
        }
Using the above code to scan the files and folders is not going as planned it generates some folders but all empty. folder structure is added some folders are created some not
Coordinator
May 28, 2015 at 2:02 AM
Before we dive into it can you please see if the built-in scanning functionality is suitabe for the purpose. Have a look at 'ReleaseFolder' and 'WildCard Files' samples.
Marked as answer by mcornille on 6/4/2015 at 1:54 AM
May 28, 2015 at 6:48 AM
sry about that i didn't see that example, i will have a look asap and let you know the result.
Jun 4, 2015 at 9:54 AM
Hi,

The 'WildCard Files' samples was exactly what i needed thanks

kind regards,

Michiel