Today, we want to find all file names from a folder.

List of file names from a fold­er | Excel Pow­er Query 05

Let’s see our fold­er. We have dif­fer­ent kinds of files and even a sub­fold­er. There is also an emp­ty fold­er called Emp­ty, which must stay emp­ty. Our task is to find all files con­nect­ed to Excel, which means that we will need to do some fil­ter­ing (Fig. 1)

Folder content
Fig. 1 Fold­er content

We know the path, so we can copy it, then go to Excel, and then use Pow­er Query, which is the sim­plest solu­tion I know. We need to go the Data tab (1), then to the Get Data com­mand (2), then to the From File (3) and From Folder (4) options (Fig. 2)

From Folder option
Fig. 2 From Fold­er option

In the new win­dow, we can find our fold­er, for exam­ple, by the nav­i­ga­tion bar, where we can paste the whole path and press Open (Fig. 3) 

Navigation bar
Fig. 3 Nav­i­ga­tion bar

We can see that Pow­er Query has pre­pared a whole batch of infor­ma­tion from the giv­en fold­er, as well as from the Sub­fold­er for us. We don’t see the Emp­ty fold­er, because there aren’t any files. In our sit­u­a­tion, it’s fine for us. Then, we need to click on the Trans­form Data but­ton (Fig. 4)

 Information prepared by Power Query
Fig. 4 Infor­ma­tion pre­pared by Pow­er Query

The Trans­form Data option gives us the chance to add some fil­ter­ing to get the data we are inter­est­ed in. In the win­dow that appeared, we can see that we can fil­ter the infor­ma­tion by the Fold­er Path (1). If we are inter­est­ed only in the main fold­er, we can check only the main fold­er (2) (Fig. 5)

Filtering by the Folder Path
Fig. 5 Fil­ter­ing by the Fold­er Path

How­ev­er, we want all fold­ers, togeth­er with the Sub­fold­er, so let’s close this fil­ter­ing and go to the Exten­sion fil­ter­ing. Since we are inter­est­ed in Excel files, we are look­ing for the ones with an .xls exten­sion. Remem­ber that Pow­er Query is case sen­si­tive, so if we have some sus­pi­cions that there may be some upper case let­ters, we have to trans­form our Exten­sion col­umn. We need to go to the Trans­form tab, then to the for­mat com­mand and the low­er­case option (Fig. 6)

Lowercase option
Fig. 6 Low­er­case option

Now, we can fil­ter this col­umn by Text Fil­ters and the Begins with option (Fig. 7)

Begins with option
Fig. 7 Begins with option

We want the text to begin with .xls, which should get all exten­sions con­nect­ed with Excel (Fig. 8)

.xls extension
Fig. 8 .xls extension

We can see that we have our cho­sen exten­sions as well as the file names also with exten­sions. This is the infor­ma­tion that we need­ed, so let’s right click on the Name bar, and select the Remove Oth­er Columns option (Fig. 9)

Remove Other Column option
Fig. 9 Remove Oth­er Col­umn option

We are left only with one col­umn, where we have file names with exten­sions. Some­times, we don’t need any exten­sions. In those cas­es, we can add one more step to Pow­er Query. We have to select the col­umn, then go to the Trans­form tab, then to the Extract com­mand and the Text Before Delim­iter option (Fig. 10)

Text Before Delimiter option
Fig. 10 Text Before Delim­iter option

Our delim­iter is just a dot, so let’s write it (Fig. 11)

Delimiter
Fig. 11 Delimiter 

Now, we have only file names with­out exten­sions. How­ev­er, let’s say that I still want those exten­sions. In such a case I need to delete this step (Fig. 12)

Deleting the last filtering
Fig. 12 Delet­ing the last filtering

Now, I go to the Home tab, click on the Close & Load com­mand, then the Close & Load to option (Fig. 13)

Going back to Excel
Fig. 13 Going back to Excel

Let’s choose the tar­get cell and select the Table radio but­ton (Fig. 14)

Data importing
Fig. 14 Data importing

Here’s the final result (Fig. 15)

 Final table
Fig. 15 Final table

https://www.youtube.com/watch?v=Dey4PzGj46A