C# and directories

vbimport

#1

How do I burn whole directories using C#.


#2

Here is my attempt. This is based off the following thread.

http://club.cdfreaks.com/showthread.php?s=&threadid=77167

It is written in VB. At the present time this code does not work. I get an exception the parameter is incorrect. Any thoughts.

private int dcnt;
private void DoIsoTrack(System.IO.DirectoryInfo dir,NEROLib.NeroFolder folder)
{
NEROLib.NeroFolder subfolder = new NEROLib.NeroFolderClass();
subfolder.Name = dir.Name;
folder.Folders.Add(subfolder);
dcnt+=1;
foreach(System.IO.DirectoryInfo dir1 in dir.GetDirectories())
{
NEROLib.NeroFolder folder2 = new NEROLib.NeroFolderClass();
folder2.Name = dir1.Name;
folder.Folders.Add(folder2);
}
foreach(System.IO.FileInfo files in dir.GetFiles())
{
NEROLib.NeroFile file = new NEROLib.NeroFileClass();
file.Name = files.Name;
file.SourceFilePath = files.FullName;
subfolder.Files.Add(file);

}

}
private void Burn_Click(object sender, System.EventArgs e)
{
Abort.Enabled =true;
Browse.Enabled=false;
Burn.Enabled=false;

try
{
NEROLib.NeroFolder folder= new NEROLib.NeroFolderClass();
drives =(NEROLib.NeroDrivesClass)nero.GetDrives(NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CDR);
drive=(NEROLib.NeroDrive)drives.Item(AvailableDevices.SelectedIndex);
NEROLib.NeroISOTrackClass isotrack=new NEROLib.NeroISOTrackClass();
isotrack.Name=“test”;
isotrack.RootFolder=folder.Folders.Item(0);

System.IO.DirectoryInfo dirFolder;
dirFolder = new DirectoryInfo (edtFileName.Text );
DoIsoTrack(dirFolder ,folder);

isotrack.BurnOptions=NEROLib.NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS;

drive.BurnIsoAudioCD(“Gentek”, “Title”, false, isotrack, null, null, NEROLib.NERO_BURN_FLAGS.NERO_BURN_FLAG_SIMULATE | NEROLib.NERO_BURN_FLAGS.NERO_BURN_FLAG_WRITE, 8, NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CD);

}
catch(Exception ex)
{
strMessages=strMessages+ex.Message+"
";
edtMessages.AppendText(strMessages);

}
}


#3

Well, I guess everyone is on spring break. I wish that I was you. Any how here is the solution I came up. I’ve tested it and it seem to work well. Have fun.

public void DoIsoTrack(System.IO.DirectoryInfo dir,NEROLib.NeroFolder folder)
{
foreach(System.IO.FileInfo files in dir.GetFiles())
{
NEROLib.NeroFileClass file = new NEROLib.NeroFileClass();
file.Name = files.Name;
file.SourceFilePath = files.FullName;
folder.Files.Add(file);
}
foreach(System.IO.DirectoryInfo dir1 in dir.GetDirectories())
{
NEROLib.NeroFolderClass folder2 = new NEROLib.NeroFolderClass();
folder2.Name = dir1.Name;
folder.Folders.Add(folder2);
DoIsoTrack(dir1,folder2);

}

}
private void Burn_Click(object sender, System.EventArgs e)
{
Abort.Enabled =true;
Browse.Enabled=false;
Burn.Enabled=false;

try
{

NEROLib.NeroFolderClass Folder= new NEROLib.NeroFolderClass();

drives =(NEROLib.NeroDrivesClass)nero.GetDrives(NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CDR);

drive=(NEROLib.NeroDrive)drives.Item(AvailableDevices.SelectedIndex);

NEROLib.NeroISOTrackClass isotrack=new NEROLib.NeroISOTrackClass();

isotrack.Name=Folder.Name;
isotrack.RootFolder=Folder;

System.IO.DirectoryInfo dirFolder;
dirFolder = new System.IO.DirectoryInfo(edtFileName.Text );
DoIsoTrack(dirFolder ,Folder);

NEROLib.NeroSpeedsClass Speed = (NEROLib.NeroSpeedsClass)drive.WriteSpeeds;
isotrack.BurnOptions=NEROLib.NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS;

drive.BurnIsoAudioCD("","",false,isotrack,null,null,NEROLib.NERO_BURN_FLAGS.NERO_BURN_FLAG_WRITE,10,NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CDRW);
}
catch(Exception ex)
{
strMessages=strMessages+ex.Message+"
";
edtMessages.AppendText(strMessages);

}
}