Separating MidiFile to Tracks

Hey i have a File which is a .midi, i have multiple tracks there with different names, how can i take each track and copy it to a new File .mid with his track name and data?
this is what i got by now:

for (int i = 0; i < midiFile.getNumTracks(); i++)
{
    // Get the current track
    MidiMessageSequence track = *(midiFile.getTrack(i));
 
    // Create a new empty MidiFile for the single track
    MidiFile singleTrackFile;
    singleTrackFile.addTrack(track);


    // Get the name of the track (if available)
    String trackName = "Track_" + String(i + 1); // Default to "Track_X" if no name is found
    for (auto& event : track)
    {
        if (event->message.isTextMetaEvent())
        {
            trackName = event->message.getTextFromTextMetaEvent();
            break;
        }
    }

    // Create the new file in the same directory as the original file with the track name
    File newFile = file.getSiblingFile(trackName + ".mid");

    // Write the single track to the new file
    if (auto outputStream = newFile.createOutputStream())
    {
        singleTrackFile.writeTo(*outputStream);
        files.add(newFile);
    }
}

Somthing went wrong… i was able to seperate the files but now it isn’t readable… like i can open it in windows Media player and it will play, but i cant drag it into DAW and im not sure why, (the orignal unsepreated file could be dragged into the daw with all the track with no problem)