I am using below code and that code gives the desired output which you are looking, please have a look.
Item itemComponent = package.GetByType(ContentType.Component);
//get the attached component ID, through which we are got the path of the required folder.
Component component = (Component)engine.GetObject(itemComponent.GetAsSource().GetValue("ID"));
PublicationTarget publicationTarget = engine.PublishingContext.PublicationTarget;
OrganizationalItemItemsFilter orgFilter = new OrganizationalItemItemsFilter(engineSession);
orgFilter.Recursive = true;
orgFilter.ItemTypes = new[] { ItemType.Component };
XmlElement List = component.OrganizationalItem.OrganizationalItem.GetListItems(orgFilter); // All component list
foreach (XmlNode node in List.ChildNodes)
{
// leave the component whose ID is same as Dummy Component
fetchComponent = engine.GetObject(node.Attributes["ID"].Value) as Component;
if (fetchComponent.Schema.Title.ToLower() == "Schema name".ToLower())
In this scenario, I attached a component with the CT and then above code picks the attached component to get the desired location of your folder. I have created this attached component inside the desired folder of which components I want to read.
Just try this solution.
Thanks