How to create a dataloader with variable-size input

I have the data folder in this 4 subfolder (cat1,cat2,cat3,cat4) I want to read data folder according to the cat (subfolder ) wise not according to data(root) folder wise. or read data according to data(root) folder but have separate out data folder according to the cat(subfolder) wise.
How design this type customeDataloader.