This single file implementation can set up a callback fired when files and/or folders are dropped onto a uifigure component.
In the callback, full file/folder names are captured for user to decide the action. Ctrl and Shift key status during the drop event are also reported.
Example to drop file/folder into uilistbox:
target = uilistbox(uifigure, 'Position', [80 100 400 100]);
DnD_uifigure(target, @(o,dat)set(o,'Items',dat.names));
Note:
1. File DnD onto uifigure works only for Matlab R2020b or later.
2. File DnD works for uifigure and figure since R2025a.
3. File DnD works for Linux since R2025a.
4. Since R2025a, the following line needs to be added into startup.m file:
try addprop(groot, 'ForceIndependentlyHostedFigures'); catch, end