Is it possible to extract the file name from attachments?

Hello!

I used to use the following formula in Airtable:

LEFT({Files},FIND("(",{Files})-1)

Would it be possible to make it work in SeaTable? (I’m asking as I tried the above formula and it didn’t work.)

If so, would it be possible to convert the result to date if the outcome already follows the ISO format (including time) but using _ (underline) as a spacer?

Example of the file name: bank_2021_11_29_07_23_27

If possible, please, let me know If I can provide more information.

Thank you for your help and attention!

I’m sorry for any inconvenience!

Hello!

Is it possible? Generally speaking, yes!
But how? It’s a little complicated. I would like to give a hint here, sorry for not offering a complete solution:

You might try the JavaScript or Python script. Here’s an example of JS:

As you can see, the script can read out the file object. The filename is in the object’s “name” value.

1 Like

Adding to Karlheinz’ post: You need a script to extract the name of the file(s) and to write them to a text column. You can then either execute the script with a button (available in the Free, Plus, and Enterprise plan) or with an automation (available exclusively in Enterprise). The automation would monitor the file column and when a file is added, the script is executed.

1 Like

Hello! :slight_smile:

Thanks for your contribution and your demonstration!

I don’t have much knowledge of programming languages, I used few times until today, but I’ll try my best to try to solve it, in case I can’t, I’ll come back to ask for help If that’s not a problem.

Just to be sure, do you think it will be possible to achieve what I described in the second part of my question?

I mean the part about turning the filename text into date automatically (I’ll probably need to use another script).

Thank you for your help and attention!

I’m sorry for any inconvenience!

Please let me know If I’m already bothering the forum too much with simple questions.

Hello!

Thanks for your contribution and for letting me know about the possibility to use buttons, I’ve seen a couple of people using them and It’s a great feature!

Do you think it will be easier to use a JS or Python script?

Also, I’m asking the same question I did in the reply to @Karlheinz just in case It goes unseen.

Just to be sure, do you think it will be possible to achieve what I described in the second part of my question?

I mean the part about turning the filename text into date automatically (I’ll probably need to use another script).

Thank you for your help and attention!

I’m sorry for any inconvenience!

Using scripts in SeaTable is not really that hard! I recommend you to take a look at the SeaTable Programming Manual to get some ideas.

For the general use cases in SeaTable, there’s no big difference in the difficulty of these two languages, you can decide for yourself. Only thing you should notice, is that we limit the running counts of python scripts for the Free and Plus (see SeaTable Prices | Subscriptions, Features and Costs - SeaTable) while for JavaScripts there’s no such limit.

For your second question: it is possible. You don’t need a script for that. Just the formula can fulfill your wish, with the date functions you can extract year, month, day etc. from a date and use the text functions to concatenate them with the underline. See the Formelreferenz - SeaTable for instructions.

1 Like

Thanks for the tips, I had already looked at the documentation, but as I said, I will try and if I don’t succeed, I will ask for help.

As for the second question, either I didn’t understand your answer properly or maybe I explained it wrong, so to clarify, my question was whether, by extracting the filename I could turn the result into a date, i.e., if the result extracted using the script is something like this: bank_2021_11_29_07_23_27, I could turn it into a date such as a date column after “cleaning it”/separating it.

Please let me know If I wasn’t clear.

Thank you for your help and attention!

I’m sorry for any inconvenience!

Now you are clear. But again, the Formula Reference I quoted above could help you to extract text from this string.

For example, in bank_2021_11_29_07_23_27, the 6th to 9th symbols are for the year, the 11th and 12th symbols are for the month, etc.

So, the following formula will return 2021:

mid("bank_2021_11_29_07_23_27", 6, 4)

If you have ever taken a look at the formula reference, you’d understand why this formula looks like this, and why it will extract “2021” from the string.

Using the same technique, you can extract the month, the day, the hour and the minute from the string. Then, using the date() function, you can turn these strings into a date.

Alright, this time I’ll hold your hand and guide you through the process:
Let’s say, you extracted your filename and saved it into a column “Filename”, then

date(mid({Filename}, 6, 4), mid({Filename}, 11, 2), mid({Filename}, 14, 2))

will return the date:

image

1 Like

Thank you for your answer.

Just to be clear, I had already read the documentation regarding the formulas, it is something I do constantly as I am still learning many of the things that SeaTable offers, I know it may have seemed like I was lazy, but I wasn’t, I just wanted to know if what I was aiming for would be possible, in the sense that the result would enable me to group or filter the column transformed into date as an actual date.

Thank you very much for detailing the answer showing the process, I had already used the formulas mid, left and right but never concatenated them as date, it worked perfectly, now I just need to try and learn how to extract the filename using the scripts.

Thank you for your help and attention!

I’m sorry for all the inconvenience!

Have a nice time you all. :slight_smile:

2 Likes

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