# Get part of url

**URL:** <https://community.glideapps.com/t/get-part-of-url/63275>\
**Category:** Ask for Help\
**Created:** [June 28, 2023, 7:28pm UTC](https://community.glideapps.com/t/get-part-of-url/63275 "2023-06-28T19:28:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wim\_De\_Coninck](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/wim_de_coninck/32/28179_2.png) [@Wim\_De\_Coninck](https://community.glideapps.com/u/Wim_De_Coninck)\
**Post date:** [June 28, 2023, 7:28pm UTC](https://community.glideapps.com/t/get-part-of-url/63275/1 "2023-06-28T19:28:40Z")

</div>

Hi, I have (Glide pages / glide table) a table with first column the URL of an uploaded file.  
In the layout-options of the file-picker, I checked “Keep file name when uploading”.  
So far so good.

But in another screen, I want to display (in a collection) all the uploaded files, but then I do not have a similar option. I can only show the whole URL.  
I think I need a second column in my table (get part of url) to retrieve only the filename, **but I do not know how.**

Any help is appreciated !

---

<div class="post-metadata">

**Author:** ![grumo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/grumo/32/34786_2.png) [@grumo](https://community.glideapps.com/u/grumo)\
**Post date:** [June 28, 2023, 8:16pm UTC](https://community.glideapps.com/t/get-part-of-url/63275/2 "2023-06-28T20:16:24Z")

</div>

You can use the Javascript column to extract the file name using this code:

```auto
  var segments = p1.split('/');

  // Get the last segment
  var lastSegment = segments[segments.length - 1];

  // Split the last segment by question mark or hash, if present
  var fileName = lastSegment.split(/[?#]/)[0];

  // Return the file name
  return fileName;

```

Where “p1” is the column with the full URL.

 ![Screenshot 2023-06-28 at 1.13.31 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/f/5f29cda4180c63e08ccbf59b5438ab7ac4616f17.png)

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [June 28, 2023, 10:51pm UTC](https://community.glideapps.com/t/get-part-of-url/63275/3 "2023-06-28T22:51:22Z")

</div>

What does your URL look like and what part do you want to isolate?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [June 29, 2023, 2:21am UTC](https://community.glideapps.com/t/get-part-of-url/63275/4 "2023-06-29T02:21:22Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/9/19176ad56fd1b42cfce226f5f7905f3b9a1390e9.png)

I believe it gives you escape characters in some cases.

```auto
var segments = p1.split('/');

// Get the last segment
var lastSegment = segments[segments.length - 1];

// Split the last segment by question mark or hash, if present
var fileName = lastSegment.split(/[?#]/)[0];

// Decode URL-encoded characters
var decodedFileName = decodeURIComponent(fileName);

// Return the decoded file name
return decodedFileName;

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/b/eb015f1c81366fcdaa1405584af649c88bcca474.png)

Added a step to decode those.

---

<div class="post-metadata">

**Author:** ![Wim\_De\_Coninck](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/wim_de_coninck/32/28179_2.png) [@Wim\_De\_Coninck](https://community.glideapps.com/u/Wim_De_Coninck)\
**Post date:** [June 29, 2023, 6:31am UTC](https://community.glideapps.com/t/get-part-of-url/63275/5 "2023-06-29T06:31:47Z")

</div>

> [@ThinhDinh](#):
>
> ```auto
> var segments = p1.split('/');
> 
> // Get the last segment
> var lastSegment = segments[segments.length - 1];
> 
> // Split the last segment by question mark or hash, if present
> var fileName = lastSegment.split(/[?#]/)[0];
> 
> // Decode URL-encoded characters
> var decodedFileName = decodeURIComponent(fileName);
> 
> // Return the decoded file name
> return decodedFileName;
> 
> ```

thanks for helping; it works 🙂

Just those extra questions (for new columns):

1. is there a way to retrieve the extension of the file (like doc, or docx, or pdf,…)
2. is there a way to retrieve the file-date ?

---

<div class="post-metadata">

**Author:** ![Dilon\_Perera](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilon_perera/32/85652_2.png) [@Dilon\_Perera](https://community.glideapps.com/u/Dilon_Perera)\
**Post date:** [June 29, 2023, 8:14am UTC](https://community.glideapps.com/t/get-part-of-url/63275/6 "2023-06-29T08:14:25Z")

</div>

> [@Wim\_De\_Coninck](#):
>
> - is there a way to retrieve the extension of the file (like doc, or docx, or pdf,…)

Try this :

```auto
var segments = p1.split('/');

// Get the last segment
var lastSegment = segments[segments.length - 1];

// Split the last segment by question mark or hash, if present
var fileName = lastSegment.split(/[?#]/)[0];

// Split the file name by dot (.) and retrieve the last element as the extension
var fileExtension = fileName.split('.').pop();

// Return the file extension
return fileExtension;

```

> [@Wim\_De\_Coninck](#):
>
> 1. is there a way to retrieve the file-date ?

You mean the file created date? I guess it’s not possible. I checked a bit and we can get the modified date with js but couldn’t get the created date. If you want the added date you can use a date column and update that column when uploading the file!

Thank you

---

<div class="post-metadata">

**Author:** ![Wim\_De\_Coninck](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/wim_de_coninck/32/28179_2.png) [@Wim\_De\_Coninck](https://community.glideapps.com/u/Wim_De_Coninck)\
**Post date:** [June 29, 2023, 2:42pm UTC](https://community.glideapps.com/t/get-part-of-url/63275/7 "2023-06-29T14:42:14Z")

</div>

> [@Dilon\_Perera](#):
>
> ```auto
> var segments = p1.split('/');
> 
> // Get the last segment
> var lastSegment = segments[segments.length - 1];
> 
> // Split the last segment by question mark or hash, if present
> var fileName = lastSegment.split(/[?#]/)[0];
> 
> // Split the file name by dot (.) and retrieve the last element as the extension
> var fileExtension = fileName.split('.').pop();
> 
> // Return the file extension
> return fileExtension;
> 
> ```

Hi [Dilon\_Perera](https://community.glideapps.com/u/Dilon_Perera),

- thanks for the extension-script; works fine !

- modified-date would be good; if you have some time to show the script…

Wim

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [June 30, 2023, 12:29am UTC](https://community.glideapps.com/t/get-part-of-url/63275/8 "2023-06-30T00:29:07Z")

</div>

> [@Dilon\_Perera](#):
>
> If you want the added date you can use a date column and update that column when uploading the file!

I think this is the easiest way, unless you truly want to know the creation date from the metadata of the file, then that’s another issue.
