If you want to request all folders and subfolders in a list or document library, you need to define additional query parameters. If you are working with the object model, you need to set the ViewAttributes property of the SPQuery object as follows:
qry.ViewAttributes = "Scope = 'Recursive'";
source share