Create a folder in disk and Burn Into it using IMA

2019-09-05 01:52发布

问题:

I'm using IMAPI2 in C# to burn a list of files to a multisession disk. But I want To be able to burn those files into a directory in the disk. Right now this is what I have

fileSystemImage = new MsftFileSystemImage();
            fileSystemImage.ChooseImageDefaults(discRecorder);
            fileSystemImage.FileSystemsToCreate =
            FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660;
if (multisessionInterfaces != null)
            {
                fileSystemImage.MultisessionInterfaces = multisessionInterfaces;
                fileSystemImage.ImportFileSystem();
            }
IFsiDirectoryItem rootItem = fileSystemImage.Root;
rootItem.AddTree(sourceDirectory,includeBaseDirectory)

This is a round about method because I have to create a temporary folder in my drive and copy all the files I want to burn into that folder and add that folder as the burn item.

I'm Using a slightly modified version of this C# IMAPI2 wrapper to implement this http://www.codeproject.com/Articles/24544/Burning-and-Erasing-CD-DVD-Blu-ray-Media-with-C-an

回答1:

you can use the method IFsiDirectoryItem::AddDirectory of the IFsiDirectoryItem interface to add a directory to the file system image on the optical media; and after that, retrieve it with IFsiDirectoryItem::get_Item method.

For example: Instead of

rootItem.AddTree(sourceDirectory,includeBaseDirectory);

Replace with something like:

rootItem.AddDirectory(directoryName);
rootItem.get_Item(directoryName, newDirItem);   

You can create multiple directory levels (just call AddDirectory on the appropriate directory item instead of rootItem).

Also, you may want to reuse existing directories on optical media if the directories already exist. You can do that by taking into account the error IMAPI_E_DUP_NAME ((HRESULT)0xC0AAB112L) returned when trying to get the directory...



标签: c# imapi