Google drive : How to split file name to json items (date ect..)

Describe the issue/error/question

Hello everyone
My project is to create a mail draft with the link of a file that have been created on the current week located in my google drive.

What is the error message (if any)?

There is no error but lack of information for my needs
This is what i see


How to split the file to create the json field

  1. extract “#xxxx” for the “project_name”
  2. extract “COPIL” for the “purpose”
  3. extrac 'XX" for the “copil_number”
  4. extract the date that is part of the name for the “dateofcreation”

one thing that will really help me is to get the week number for the “dateofcreation”

Please share the workflow

Node 1 : NumWeek of this week (set node with {{$today.toFormat('WW')}} for expression

Node 2 : the drive node
a/ Get the file list based on my filter with their names
Objects to split in node 2:
#MATRIX COPIL 33 agenda Sun Nov 20 2022 18:00:00 GMT-0500 (Eastern Standard Time)
#CQI2022 COPIL 8 Tue Nov 22 2022 00:00:00 GMT+0100 (Central European Standard Time)
#GED2023 Copil 10 Mon Nov 21 2022 18:00:00 GMT-0500 (Eastern Standard Time)

Node 3 : Set week number for the file
Node 4 : IF week number comparaison
a/ create an If node to keep only files with the same weeknumber of the current one ({{DateTime.now().toFormat("WW");}})

Node 5 : Gmail draft
a/ Create a email draft with the link of the file location and other JSON item

the flow is not yet created as i 'm stuck with the node 2 i’m not dev. and don’t know how to handling it.

Many thanks for your help

Information on your n8n setup

  • n8n version: n8n Version 0.182.0
  • Database you’re using (default: SQLite): google drive
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: desktop app

I did my research this week-end and i can share my findings for the solution:

I use a Code node with the code below

' split each string separated by space
const parts = item.name.split(' ');
for (let i=0;i<parts.length;i++) {
  item[`var${i+1}`] = parts[i];
}

return item;

I have in result :


{
"id":
"1UxlG2lKgTDROs5U-rjfrIaQYvB-b3Eat",
"name":
"#MATRIX COPIL 33 agenda Sun Nov 20 2022 18:00:00 GMT-0500 (Eastern Standard Time)",
"var1":
"#MATRIX",
"var2":
"COPIL",
"var3":
33,
"var4":
,
"var5":
"agenda",
"var6":
"Sun",
"var7":
"Nov",
"var8":
20,
"var9":
2022,
"var10":
"18:00:00",
"var11":
"GMT-0500",
"var12":
"(Eastern",
"var13":
"Standard",
"var14":
"Time)"
},

Use a Rename Keys node to define the proper json.item
RenameKeys

for the : one thing that will really help me is to get the week number for the “dateofcreation”
I won’t use it because the only solution i have is to merge the items of the date and reformat it as date then do comparason with a set node with expression
{{$today.toFormat('WW')}}

Hope it helps others :slight_smile:

1 Like

Hi @Thierry66, great to see you’ve figured it out and thank you so much for sharing your solution :bowing_man:

Did you solve the getting the week number from your dateofcreation value as well? If not, something like below could do the job I think:

I am using a regular expression here to extract the date and time, then parse it using Luxon’s fromFormat (since it didn’t seem to match any standard format supported by Luxon). The expression could use some tweaking I think, but the basic idea should work.

1 Like

Hello @MutedJam

I did actually as i’m not developer i used a different angle see below

Note that the node in between is not needed for the week number but i wanted to have also the date item.

Many thanks for sharing a way to achieve it. :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.