You have to do this programmatically and via the convert task.
Programmatically, you have to enable the folder references property on the database. E.g.
Dim session as NotesSession Dim db As NotesDatabase Set db = session.CurrentDatabase db.FolderReferences = True
This enables Notes to track which folders documents are put into after you enable this flag. However, all the foldered documents before setting this flag will be missing their folder references. To determine which folders documents are in, you have to run this on the server console:
load convert -m <database>(R6 or R7)
load convert -e <database>(R5)