So, I manage to index files from folders with the following formula :
=IFERROR(INDEX(E_Standard,ROW()-1),"")
Where "E_Standard" is a Name for =FILES(Standard!$A$2)
and in cell "Standard!$A$2" you have my folder path : "N:\\Guitar stuff\\Vids\\Doable\\Standard\\E Standard\\Redone\*"
.
All of this were fine until now, because for some reasons, the alphabetical order is now not respected (as seen in the screenshot below).
All the other tabs works fine but none of them approach the number of files this one does (114 for the second with the most files, while this one is at 648)
Could it be any reason to why it doesn't list it in alphabetical order anymore ?
I tried to clean the tab and put the formula again, it didn't change anything. I expected some problem with the auto-refresh
I tried to reload the folder's content, no effect either, I expected some problem on the first reload of the folder
For Multiple Paths
2024-09-22
Paths could be in a single column or row.
folderPaths
- range containing the paths needlet
fxFileNames = (path) =>
let
Source = Folder.Contents(path),
keepNameCol = Table.SelectColumns(Source, {"Name"}),
nameList = Table.ToList(keepNameCol)
in
nameList,
fxExpandAll = (t as table, optional colNum as number) =>
let
colNames = Table.ColumnNames(t),
Index = if colNum = null then 0 else colNum,
expand = Table.ExpandListColumn(t, colNames{Index}),
nextCol = Index + 1,
repeat = if nextCol < List.Count(colNames) then @fxExpandAll(expand, nextCol) else expand
in
repeat,
paths = Excel.CurrentWorkbook(){[Name = "folderPaths"]}[Content],
pathsAsCols = if Table.RowCount(paths) > 1 then Table.Transpose(paths) else paths,
colNames = Table.ColumnNames(pathsAsCols),
nameListInCols = Table.TransformColumns(
pathsAsCols,
List.Transform(colNames, (col) => {col, each fxFileNames(_)})
),
expandAll = fxExpandAll(nameListInCols)
in
expandAll
getFileNamesInColumns
Please refresh when you update the paths or the range (from Query > Refresh)
I have used Ron's recursive function for expanding columns.
Get File Names with Power Query in Excel 2016
folderPath
let
path = Excel.CurrentWorkbook(){[Name = "folderPath"]}[Content]{0}[Column1],
Source = Folder.Contents(path),
keepNameCol = Table.SelectColumns(Source, {"Name"}),
sortedNames = Table.Sort(keepNameCol, {{"Name", Order.Ascending}})
in
sortedNames
See the whether names are sorted as exepected.
Results from Power Query need to be manually refreshed whenever there's a change (either to the folder path or to the contents of the folder.)