-
Notifications
You must be signed in to change notification settings - Fork 4
/
Folder.FilesFormatted.pq
81 lines (72 loc) · 3.14 KB
/
Folder.FilesFormatted.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Folder_FilesFormatted
let
/*
About:
calls Folder.Files(path) , then cleans up the resulting table
- simplifies and sorts the default table
- adds filename Full Path, and Binary Metadata (In addition to Attributes)
- ignores temp files
Example
= Folder_FilesFormatted( Folder.Files("c:\foo\bar") )
Example
options = [ keepAllColumns = true, noCustomColumns = true ],
Source = Folder_FilesFormatted(
Folder.Files("c:\foo\bar"), options
)
note:
at first it was going to take a filepath then return the results
but to make it work easier with data source privacy I'm trying out passing the table
I could use 'source as any' to use both behaviors.
*/
fnFolder_FilesFormated =
(source as table, optional options as nullable logical) as table =>
let
keepAllColumns = options[keepAllColumns]? ?? false,
// don't remove default columns
// noCustomColumns = options[noCustomColumns]? ?? false, // disables addind new columns: Table.AddColumns
/*
The current Api returns these columns:
Attributes, Content, Date accessed, Date created, Date modified,
Extension, Folder Path, Name
*/
#"Remove Extra Columns" =
let
// experimenting with half on formatting and alignment
t = Table.SelectColumns(
source,
{ "Date modified", "Attributes", "Folder Path", "Name", "Content" })
in
if keepAllColumns then source
else t,
#"Hide Temp Files" = Table.SelectRows(
#"Remove Extra Columns",
(row) =>
not Text.StartsWith(row[Name], "~$")
),
#"Add Binary Metadata" = Table.AddColumn(
#"Hide Temp Files",
"Binary Metadata",
(row) as record =>
Value.Metadata(row[Content]),
type record
), #"Add Full Path" = Table.AddColumn(
#"Add Binary Metadata",
"Full Path",
(row) as text =>
row[Folder Path] & row[Name],
type text
),
#"Reorder Columns" = Table.ReorderColumns(
#"Add Full Path",
{ "Name", "Full Path", "Date modified", "Attributes", "Binary Metadata", "Folder Path", "Content" } ),
#"Sorted Rows" = Table.Sort(
#"Reorder Columns", {
{ "Date modified", Order.Descending },
{ "Name", Order.Ascending }
}
),
FinalTable = #"Sorted Rows"
in
FinalTable
in
fnFolder_FilesFormated