First of all, I thought that the question title is somewhat misleading, because there is no folder structure in the Gmail account to keep. For all I'm concerned, it's supposed to be created.
That being said, I believe copying your local folder structure to your Gmail account is probably the most simple approach. To showcase the procedure, I created a fresh Gmail account and set it up in Thunderbird:
I made sure to leave messages on the server, which is probably how your account was set up as well:
Now, the first thing that comes to mind is
Set up filters in Gmail to replicate your folders
If you always sorted your mail in Thunderbird manually, this is probably not going to be your solution. But if you utilized the Message Filters in Thunderbird to sort your mail into folders, it's probably the easiest path to set up filters in Gmail to apply Labels to your mail.
This will sort your current email and also sort future emails into the correct folder. Something that you will probably find very helpful. Let's look at an example:
So, this is a filter that looks for the word "Amazon" either in the subject or the sender address. Let's set up the same filter in Gmail. However, it should be noted that the folders in Gmail work a bit different from the folders in Thunderbird. A mail simply has a label attached to it. All mails with the same label can then be seen in the folder assigned to that label.
But this doesn't mean the mail disappears from your inbox. So, for proper sorting, you're going to want to make sure to not place the mail in your inbox. We'll take care of that in a second. Let's begin with the first step.
Click the little triangle in the search box.
In the resulting form, we can define our search, which we will then turn into our filter. Define the search as shown below. And then click Create filter with this search.
In the next step, you're going to want to check Skip the Inbox (Archive it). This will make sure the mail only appears in the designated folder.
You'll also want to apply your label here. To do so, check the box Apply the label, then click Choose label... and then New label.... I'm going to name my label Amazon.
Last, but certainly not least, you're going to want to check the box Also apply filter to 1234 matching conversations. This will move all your existing messages from the inbox, to which the filter applies, to the new folder.
If you now force Thunderbird to reload the IMAP folder structure, you'll see your new Amazon folder with all the mail sorted into it.
I sort my mail manually
So you don't use message filters in Thunderbird and you also don't plan to set them up on Gmail. You simply want your existing local folders to appear in Gmail exactly as they currently do locally, while avoiding to create any duplicate mail items.
The solution has already been given by Nicu Zecheru, just copy all the local mail items to the IMAP account.
However, you've noted 2 issues with that procedure.
- You end up with duplicate emails in Gmail
- Nested folders don't seem to come across very well.
Regarding 1, I would simply clear my All Mail folder before moving the mail over. Then you end up with only your (previously) local mail.
Regarding 2, I was unable to reproduce this issue. I copied my archive of Stack Exchange newsletter to the newly created account. And the nested folder in it appeared just fine in Gmail. Just make sure to copy your folders to the root of your account and not nest them within the Inbox or [Gmail] folders.
Thunderbird
Gmail