foreach (SPFolder folder in list.Folders) {
if (folder.ItemCount > 0) {
foreach (SPFile file in folder.Files) {
SPListItem item = file.Item;
// Do stuff with your item here.
}
foreach (SPFolder subfolder in folder.SubFolders) {
// Do stuff with your folder here.
// Think about perhaps using recursion if you want to list the items from this folder and beyond
}
}
}
Because we're using foreach, we don't really need to check if the itemcount is more than 0. But this is just an example to allow you to identify which folders have items and how you can access them