# Fmod Studio import CSV file to create Events

**URL:** <https://qa.fmod.com/t/fmod-studio-import-csv-file-to-create-events/20606>\
**Category:** FMOD Studio\
**Created:** [August 30, 2023, 12:07pm UTC](https://qa.fmod.com/t/fmod-studio-import-csv-file-to-create-events/20606 "2023-08-30T12:07:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenken0615](https://avatars.discourse-cdn.com/v4/letter/k/e36b37/32.png) [@Kenken0615](https://qa.fmod.com/u/Kenken0615)\
**Post date:** [August 30, 2023, 12:07pm UTC](https://qa.fmod.com/t/fmod-studio-import-csv-file-to-create-events/20606/1 "2023-08-30T12:07:56Z")

</div>

I want to write a Js script which can import csv file. But i can not find a function to open a file explorer or browser to select a csv file to import.

i could use studio.system.getFile(filepath); to open a file, but how to get this filepath?

Could any one help me? Thank you so much!

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [August 30, 2023, 11:37pm UTC](https://qa.fmod.com/t/fmod-studio-import-csv-file-to-create-events/20606/2 "2023-08-30T23:37:39Z")

</div>

Hi,

> [@Kenken0615](#):
>
> I want to write a Js script which can import csv file. But i can not find a function to open a file explorer or browser to select a csv file to import.
> 
> i could use studio.system.getFile(filepath); to open a file, but how to get this filepath?

You can use the filesystem “Open” window with the following code:

```auto
var path = "";

studio.ui.showModalDialog({
            windowTitle: "Open a file",
            widgetType: studio.ui.widgetType.PathLineEdit,
	text: "",
	label: "Please select a file to open and close the window when done",
	onEditingFinished: function() {
		path = this.text();
	}
});

```

On selecting a file and closing the Modal Dialog Window in FMOD Studio, the filepath will be assigned to the `path` variable.

Also, I happen to have a script on hand which opens a text file containing a list of events in folder delimited like so:

```auto
folder/subfolder1/event1
folder/subfolder1/event2
folder/subfolder2/event3
folder/subfolder2/event4

```

and generates the folder and events in the FMOD Studio project based on that. It’s not exactly what you need, since you’re using a CSV that is likely delimited differently, but it may serve as a helpful reference:

```auto
studio.menu.addMenuItem({
	name: "Events From File",
	execute: function() {
		createEventsFromFile();
	}
});

function createEventsFromFile(){
	var filePath = studio.project.filePath;
	filePath = filePath.substr(0, filePath.lastIndexOf("/") + 1) + "/eventList.txt";

    // Open txt file at project path, returning early if file cannot be opened
    var textFile = studio.system.getFile(filePath);
    if (!textFile.open(studio.system.openMode.ReadOnly)) {    
        alert("Failed to open file {0}".format(filePath));
        console.error("Failed to open file {0}.".format(filePath));
        return;
    }

	// Read entire text file
	var text = textFile.readText(textFile.size());
	// Split text to lines
	var lines = text.split('\n');

	// For each line, split event paths into individual elements
	lines.forEach(function(line){
		var lineElements = line.split('/');	

		// For each folder/event
		for(var i = 0; i < lineElements.length; i++) {

			// Generate paths of folder/event and parent folder
			var folderPath = lineElements.slice(0, i + 1).join('/');
			var parentFolderPath = lineElements.slice(0, i).join('/');

			// Try to retrieve existing folder/event and parent folder from project 
			var folder = studio.project.workspace.masterEventFolder.getItem(folderPath);
			var parentFolder = studio.project.workspace.masterEventFolder.getItem(parentFolderPath);

			// If existing folder/event doesn't exist, create new, and assign appropriately
			if (typeof folder == 'undefined') {
				if (i < lineElements.length - 1){
					var folder = studio.project.create('EventFolder');
					folder.name = lineElements[i];
					if (parentFolder != 'undefined'){
						folder.folder = parentFolder;
					}
				} else {
					var folder = studio.project.create('Event');
					folder.name = lineElements[i];
					if (parentFolder != 'undefined'){
						folder.folder = parentFolder;
					}
				}
			}
		}
	});

	textFile.close();
}

```

Let me know if you run into any issues.

---

<div class="post-metadata">

**Author:** ![Kenken0615](https://avatars.discourse-cdn.com/v4/letter/k/e36b37/32.png) [@Kenken0615](https://qa.fmod.com/u/Kenken0615)\
**Post date:** [September 1, 2023, 6:52am UTC](https://qa.fmod.com/t/fmod-studio-import-csv-file-to-create-events/20606/3 "2023-09-01T06:52:18Z")

</div>

This Would be Great help! May ask another question?  
If i know the file path right now, may i open the file folder? such as “reveal in file explorer”

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [September 4, 2023, 2:01am UTC](https://qa.fmod.com/t/fmod-studio-import-csv-file-to-create-events/20606/4 "2023-09-04T02:01:34Z")

</div>

> [@Kenken0615](#):
>
> If i know the file path right now, may i open the file folder? such as “reveal in file explorer”

The following should open Windows Explorer and select your file given a filepath:

```auto
var path = "C:\\Your\\File\\Path\\Here.csv";
studio.system.startAsync("explorer", {workingdir: "", args: ["/select,", path]});

```

---

<div class="post-metadata">

**Author:** ![Kenken0615](https://avatars.discourse-cdn.com/v4/letter/k/e36b37/32.png) [@Kenken0615](https://qa.fmod.com/u/Kenken0615)\
**Post date:** [September 7, 2023, 11:32am UTC](https://qa.fmod.com/t/fmod-studio-import-csv-file-to-create-events/20606/5 "2023-09-07T11:32:29Z")

</div>

Thank you so much!
