# How to Prevent Initial Folder Query from Searching Subfolders



## lager1001 (Jun 16, 2020)

I am querying a folder, a specific folder for files within it only. I am not interested in the files contained under the subfolders. The problem is that there are dozens of subfolders and hundreds of files in those folders. It is taking entirely too long for my folder query to go through these before I can apply the query filters to exclude them. Is there a way to initially have the query only point to the specific folder I am wanting and not any of its subfolders? I don't want the query to even look at those.


----------



## sandy666 (Jun 16, 2020)

maybe use Folder Path directly to selected folder, eg.
From Folder:
Source: C:\Users\user\Desktop\excel_solutions
and all sub folders

to 
From Folder
Source: C:\Users\user\Desktop\excel_solutions*\Excel\excel answers\PQTest\*


----------



## macfuller (Jun 23, 2020)

To be a bit more specific along Sandy's answer, as you build your query in Power Query, there is a column called Folder Path you see in your query once you have named the folder you want to search.  Here is an example from one of my drives, where the Match Exception folder is the parent and I want to exclude the files in the archive folder underneath.






Just as you may filter file names in the Source.Name column to only take .xlsx or .csv files, you can use the same filter on the Folder Path column.
Add a command along the lines of the following to limit your files only to those items in the folder you want.  In my case it is:

        Table.SelectRows(YourPreviousStep, each ([Folder Path] = "S:\OFP\SCM Logistics Operations\Sources\Match Exception\"))


----------

