Trouble burning a Folder recursiv

Hello !

Ich have a Problem to create a IsoTrack in a recursive function.
I use NeroCom.dll and VB.NET!

I’ll have to burn a Folder on CD as Backup.
Here is my Code/Idea:

Private Sub Burn_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Burn.Click ’ Button der die aktion auslößt! btnAbort.Enabled = True
Burn.Enabled = False
'the NEro Com Object
Dim drives As NEROLib.INeroDrives
drives = nero.GetDrives(NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CDR)
drive = drives.Item(AvailableDevices.SelectedIndex)

’ Isotrack Root Folder!
Dim Folder = New NEROLib.NeroFolder()
’ Hier wird nun das entscheidende Objekt erstellt, welches den Inhalt der DatenCD darstellt
Dim isotrack As NEROLib.NeroISOTrack
isotrack = New NEROLib.NeroISOTrack()
isotrack.Name = “Backup_CD”
isotrack.RootFolder = Folder

’ !Here i will use the recursive function by reference! So that the orginal isotrack is modified !

recurse(New System.IO.DirectoryInfo(“d:\downloads”), isotrack, Folder, Me.ListBox1)

’ Inizialise Burning
isotrack.BurnOptions = NEROLib.NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS + NEROLib.NERO_BURN_OPTIONS.NERO_BURN_OPTION_USE_JOLIET
drive.BurnIsoAudioCD(“Pop Star”, “Title”, 0, isotrack, Nothing, Nothing, NEROLib.NERO_BURN_FLAGS.NERO_BURN_FLAG_SIMULATE + NEROLib.NERO_BURN_FLAGS.NERO_BURN_FLAG_WRITE, 4, NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CD)
GoTo quit
handle_error:
strMessages = strMessages & Err.Description & Chr(13) & Chr(10) & nero.LastError
edtMessages.Text = strMessages
quit:
End Sub
Private dcnt As Integer
Private Sub recurse(ByVal dir As System.IO.DirectoryInfo, ByVal IsoTrack As NEROLib.NeroISOTrack, ByVal folder As NEROLib.NeroFolder, ByVal lb As ListBox)
dcnt += 1

’ Directorys
Dim dir1 As System.IO.DirectoryInfo
For Each dir1 In dir.GetDirectories()
’ Für jeden unterordner ein ordner im isotrack erstellen
recurse(dir1, IsoTrack, folder, lb)
Next

’ The Nero Object for the files in eacvh dir
Dim fi As System.IO.FileInfo
Dim file As NEROLib.NeroFile
For Each fi In dir.GetFiles()
file.Name = fi.Name <-- HIER DIE System Exeption!!!
file.SourceFilePath = fi.FullName
folder.Files.Add(file)
’ For visual controll in form!
lb.Items.Add(fi.FullName)
lb.Items.Add(fi.Name)
Next
End Sub

I want to give the isotrack by reference so that the original isotrack is updated by my recursive function!

Anyone a Idea? I become System Exeptions. There must be a function to create a isotrack in a recursive function…

Please help.(My English is not so good, because i’m from germany!)

Dim fi As System.IO.FileInfo
Dim file As NEROLib.NeroFile
For Each fi In dir.GetFiles()
file.Name = fi.Name <-- HIER DIE System Exeption!!!
file.SourceFilePath = fi.FullName
folder.Files.Add(file)

What kind of exception is occurring?

Shouldn’t there be a:

Set file = New NeroLib.NeroFile

or whatever is equivalent in VB.NET? If not, please specify what kind of error is occurring more precisely.

StackOverflowExeption
OK to answer your question:

I have a staxkowerflowexeption in the Line where i want to create the file object, to add to the rootFolder.

Do you habe an Example for me, how to burn a Dir recursivly?
Is’nt it better to store the File and Dir Info in a 3 Dimensional Array.

And then create a IsoTrack outbound the recursive Function?

Greets from Germany

snitch

Originally posted by snitch
[B]StackOverflowExeption
OK to answer your question:

I have a staxkowerflowexeption in the Line where i want to create the file object, to add to the rootFolder.[/B]

I am really sorry but this doesn’t help much. Can you please single out the exact line where this happens? Your initial code comments imply that the exception is occurring in the

file.Name = fi.Name <-- HIER DIE System Exeption!!!!

part of your code. Now you refer to the line where you supposedly create the object, but the fact is you are not creating it anywhere. I previously asked if there was a need to explicitly create the object (as in VB6) and you said nothing about this.

Unless the object is automatically created in VB.NET, the fact that <i>file</i> variable is uninitialized might be part of your problem.

But then again, if there is a stack overflow, it would be really helpful to know <i>exactly</i> where it occurs.

[B]Do you habe an Example for me, how to burn a Dir recursivly?
Is’nt it better to store the File and Dir Info in a 3 Dimensional Array.

And then create a IsoTrack outbound the recursive Function?
[/B]

It is not very clear what you meant here. Please clarify…

OK.

My Wish is to burn a folder whith content i don’t know.
My Idea was to create a recursive function to create the isotrack object and add the file and folder objects by reference.
After this i want to burn the isotrack on cd.

Do you have a Sample for me, how to burn a Directory whith nerocom.dll?

I have found all errors in the VB6 to VB .NET converted NeroFiddlesCom. My Events are all ok and do their jobs.

But i don’t know how to burn a Directory.
If you will, i can give you my sample again, i have burned all directorys on cd, but my ideas are empty if i would add the files in the directorys on th isotrack …

Ok, it is a bit more clear now. I think you are on the right track.

I have managed to get your code working. You are indeed missing an object instantiation. Funny enough, VB.NET app seems to actually crash instead of reporting back to environment that <b><i>file</i></b> variable is <i>Nothing</i>. Anyway, if you add the middle line from the code below to your code, things should start working.


For Each fi In dir.GetFiles() 
file = New NeroLib.NeroFile
file.Name = fi.Name <-- HIER DIE System Exeption!!!!

Hello again,

You have found the right error in my code.

I coul’d complete the function whith now burns my content from a Dir on cd.

But now a new Problem is occured.

My input is c: est

And the Product on CD Rom is

test/
dir1/
dir1/
.file1

dir2/

Cann you tell me how to burn the content whithout the test folder? It is the given dir c: est !

I only want to burn c: est… as rootdirs in my isotrack! :bow:

Here is my code again:

Private dcnt As Integer
Private Sub DoIsoTrack(ByVal dir As System.IO.DirectoryInfo, ByVal lb As ListBox, ByRef folder As NEROLib.NeroFolder)
Dim subfolder As New NEROLib.NeroFolder()
subfolder.Name = dir.Name
folder.Folders.Add(subfolder)
dcnt += 1
’ Process subdirectories
Dim dir1 As System.IO.DirectoryInfo
For Each dir1 In dir.GetDirectories
DoIsoTrack(dir1, lb, subfolder)
Next
’ List files in each subdirectory
Dim fi As System.IO.FileInfo
For Each fi In dir.GetFiles()
Dim file As New NEROLib.NeroFile()
file.Name = fi.Name
file.SourceFilePath = fi.FullName
subfolder.Files.Add(file)
Next
End Sub

Private Sub Burn_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Burn.Click
btnAbort.Enabled = True

    Folder = New NEROLib.NeroFolder()
    Dim drives As NEROLib.INeroDrives
    drives = nero.GetDrives(NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CDR)
    drive = drives.Item(AvailableDevices.SelectedIndex)

    ' IsoTrack initialisieren
    Dim isotrack As New NEROLib.NeroISOTrack()
    isotrack.Name = "TestTrack"

’ Here i give the IsoTrack root folder
’ This is c: est but i want to have the subdirs in isotrack.rootfolders!!!

    isotrack.RootFolder = Folder

’ Here my function is active ByReference on the folder object!!!
DoIsoTrack(New System.IO.DirectoryInfo(Me.txtInputDir.Text), ListBox1, Folder)

    isotrack.BurnOptions = NEROLib.NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS + NEROLib.NERO_BURN_OPTIONS.NERO_BURN_OPTION_USE_JOLIET
    drive.BurnIsoAudioCD("Pop Star", "Title", 0, isotrack, Nothing, Nothing, NEROLib.NERO_BURN_FLAGS.NERO_BURN_FLAG_WRITE, 32, NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CD)
    GoTo quit

handle_error:
strMessages = strMessages & Err.Description & Chr(13) & Chr(10) & nero.LastError
edtMessages.Text = strMessages
quit:
End Sub

Originally posted by snitch
[B]But now a new Problem is occured.

My input is c: est

And the Product on CD Rom is

test/
dir1/
dir1/
.file1

dir2/

Cann you tell me how to burn the content whithout the test folder? It is the given dir c: est !

I only want to burn c: est… as rootdirs in my isotrack! :bow:
[/B]

Please replace the code below with a relevant portion of your code. This should be enough for a start. The way you coded it, all files from all subfolders are placed in the root of the disc. The code below should preserve the folder structure.


        For Each dir1 In dir.GetDirectories()
            Dim folder2 = New NEROLib.NeroFolder()
            ' Für jeden unterordner ein ordner im isotrack erstellen 
            recurse(dir1, IsoTrack, folder2)
            folder2.Name = dir1.Name
            folder.Folders.Add(folder2)
        Next

I think i have told my problem not enought correctly.
My code i’ve posted two messages ago is working correctly!
The Folderstructure i give is the same on my CD after burning!

The only problem is, that the startfolder in path c: est is the only folder on my CD rootdir! In This test Folder on CD are stored all Files from my c: est Folder on HDD.

I only want to behind all Files and Subdirs below c: est\ …
For example: If i have two folders in c: est Test2 and Test3 whitch contains files and folders, i would have a CD witch has only Test2 and Test3 in Rootdir!
Not test and under this folder test2 and test3.

Understand my Question?

I think i have told my problem not enought correctly.
My code i’ve posted two messages ago is working correctly!
The Folderstructure i give is the same on my CD after burning!

You are right. I corrected your previous code. That one had a problem with recursion. Your most recent code snippet is ok.

The only problem is, that the startfolder in path c: est is the only folder on my CD rootdir! In This test Folder on CD are stored all Files from my c: est Folder on HDD.

Ok, I think I understand. You don’t want <b>test</b> folder itself to appear in the root. You want the root to contain whatever is in the <b>test</b> folder.

You should add the following line after a <b>DoIsoTrack</b> call.


        isotrack.RootFolder = Folder.Folders.Item(0)

This is just a quick workaround to get your particular code working. When you learn what the root folder actually is, you will probably rethink your implementation a bit. The actual requirements are that the root folder is a <i>dummy</i> folder whose contents (files and folders) are written in the root of the disc. It is dummy because all that matters is its files and folders while its name is ignored.

In your particular example, you create a root folder explicitly and then recursively collect all other folders <b>including</b> the starting folder (<b>c: est</b>). If you want files and folders below <b>c: est</b> to appear in the root of the disc, you need to make <b>c: est</b> be the root folder. This is exactly what I did in the modification.

OK I understand, you are very patient whith my german english, thanks! My Project is running correctly!
:smiley: :slight_smile: :bigsmile: