question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it easier for functions to access other files in their folder

See original GitHub issue

This came from internal Yammer group.

If a function folder contains a data.txt file, it is currently difficult to read that file from the function code. Typically, common patterns to do this would be:

  1. Rely on the current folder being set to the function folder as it runs
  2. Rely on some environment variable pointing to the function folder

Unfortunately, these can’t work today since all functions run in the same process. We need to come up with an approach to solve this.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
davidebbocommented, Nov 15, 2017

@abergs See here for a sample that does that.

3reactions
briandunningtoncommented, Jun 5, 2017

The properties on the ExecutionContext are very helpful for C# projects. But I have another question/feature request:

I have some static files as part of my project (custom encoder presets stored as json or xml, etc) that I want to File.Read() into my function at runtime. Given that C# now uses attributes instead of folders, I keep all of my individual functions as .cs files in the root of my project along side the static files. ExecutionContext.FunctionDirectory only has function.json in it, and if i …/ up one level, my project-level static files are not in that folder. It turns out that they are in …/bin/ relative to the function folder.

However, when running the project locally using the VS Tools, the project .dlls and other output are not in a ‘bin’ subfolder but at the root of the output directory. So I cant reference the file using the same path locally and when deployed.

PROJECT -MyFunction1.cs -MyFunction2.cs -SomeOtherFile.json

How can I reference SomeOtherFile.json from my function both locally and when deployed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to organize files and folders
Start organizing your files by creating a logical, hierarchical folder structure. The best folder structure will mimic the way you work. For ...
Read more >
Windows Basics: Working with Files
You can view and organize files and folders using a built-in application known as File Explorer (called Windows Explorer in Windows 7 and...
Read more >
python - Importing files from different folder
From what I know, add an __init__.py file directly in the folder of the functions you want to import will do the job....
Read more >
Access documents and other files from shared storage
Quickly bring your app to life with less code, using a modern declarative approach to UI, and the simplicity of Kotlin. ... Start...
Read more >
Python Write to File – Open, Read, Append, and Other ...
One of the most important functions that you will need to use as you work with files in Python is open() , a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found