# Returning Filename from File Explorer Component

**URL:** <https://forum.inductiveautomation.com/t/returning-filename-from-file-explorer-component/6968>\
**Category:** Ignition\
**Created:** [August 1, 2013, 4:26pm UTC](https://forum.inductiveautomation.com/t/returning-filename-from-file-explorer-component/6968 "2013-08-01T16:26:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![randomranger](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@randomranger](https://forum.inductiveautomation.com/u/randomranger)\
**Post date:** [August 1, 2013, 4:26pm UTC](https://forum.inductiveautomation.com/t/returning-filename-from-file-explorer-component/6968/1 "2013-08-01T16:26:28Z")

</div>

When using the file explorer component, is there a way to get the name of the selected file within the File Explorer component? I failed to see a property or method that would do this, I know that there is a selected path method, but I need just the filename.

EDIT: Further than returning just the filename, is it possible to return a select number of the directors, for example the first 3 folders or the last 3 folders?

EDIT: I developed a bit of code that would do this, but it is not optimal. I would have preferred that there be a dedicated API method. However if anyone else needs to know how to do this here is my code:

`counter = 0
for counter in range(0, len(selectedPath)):
	selChar = selectedPath[(-counter - 1)]
	if selChar == '\\' or selChar == '/':
		filename = selectedPath[-counter:-4]
		print filename
		break`  
For now though, unless I am told otherwise, I will leave this post open incase someone finds a function or other that will return the filename and would like to post it up on here.

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [August 7, 2013, 9:03pm UTC](https://forum.inductiveautomation.com/t/returning-filename-from-file-explorer-component/6968/2 "2013-08-07T21:03:19Z")

</div>

rfind is what you want:

```auto
sPath = event.source.parent.getComponent('File Explorer').selectedPath
sFileName = None
if sPath.rfind(".") != -1:
	if sPath.rfind("\\") != -1:
		sFileName = sPath[sPath.rfind("\\")+1:sPath.rfind(".")]
	elif sPath.rfind("/") != -1:
		sFileName = sPath[sPath.rfind("/")+1:sPath.rfind(".")]
if sFileName == None:
	sFileName = ""
print sFileName
```

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [August 7, 2013, 9:39pm UTC](https://forum.inductiveautomation.com/t/returning-filename-from-file-explorer-component/6968/3 "2013-08-07T21:39:45Z")

</div>

I also like this, if you know which system you are on and don’t mind the file extension:

```auto
fileName = filePath.split("\\")[-1]
```

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [August 22, 2013, 11:36pm UTC](https://forum.inductiveautomation.com/t/returning-filename-from-file-explorer-component/6968/4 "2013-08-22T23:36:08Z")

</div>

I use the split() method. It returns a nice list for you to do whatever you want with. There’s nothing built into the component like this.
