Forum Discussion
Skip source paths that do not exist
Hi pszpecht - Update the CheckFolderExists function to handle exceptions for missing folders more gracefully.
please find the attache pq editor code.
let
// Reference the table containing folder paths
FolderPathsTable = FolderPathsTable,
BufferedFolderPathsTable = Table.Buffer(FolderPathsTable),
// Function to check if a folder exists
CheckFolderExists = (folderPath as text) as logical =>
try
Folder.Files(folderPath) <> null
otherwise
false,
// Filter rows to keep only those paths containing "xxx -"
FilteredRows = Table.SelectRows(BufferedFolderPathsTable, each Text.Contains([FolderPath], "xxx -")),
// Keep only rows where the folder exists
ExistingPaths = Table.SelectRows(FilteredRows, each CheckFolderExists([FolderPath]) = true),
// Add a column to retrieve file metadata for each valid path
GetFiles = Table.AddColumn(ExistingPaths, "Files", each try Folder.Files([FolderPath]) otherwise null),
// Remove rows where the "Files" column is null (for invalid paths)
ValidFiles = Table.SelectRows(GetFiles, each [Files] <> null),
// Combine file data from all valid folders
CombineFiles = Table.Combine(ValidFiles[Files]),
// Select relevant columns for the output
RemovedOtherColumns = Table.SelectColumns(CombineFiles, {"Name", "Folder Path"})
in
RemovedOtherColumns
Modified one.
Hope this helps.
rajendraongole1 I'm impressed by this quick turnaround and really great explanation of the code (thank you!), however, sadly I still get the DataSource.NotFound error.
Maybe there should be a different approach taken completetly?