CSV.read() won't accept just a file name?


I’m trying to load a .csv file into a DataFrame using:
data = CSV.file(“filename.csv”) |> DataFrame
Where “filename.csv” exists in the same folder as my Julia program file.

According to online resources, this seems to work without problem, but Julia throws an error back that it doesn’t have a valid filename. It does work if I use “C:\documents\…\subfolder\filename.csv”, but for future applications, this won’t be acceptable when I move folders around.

What’s the appropriate naming convention/command call to make sure I only need to tell it to load a file from the same folder?



pretty sure this should work! are you sure, that your julia is running in the right folder? check, pwd() … if that’s the wrong folder, you can usually fix it with cd(@__DIR__)



When you refer to a file by name in julia (or python or just about any other language), the program looks for that file relative to where the julia program was run from. If you launched Julia from the cmd terminal, then thst will be whatever folder your terminal was in when you ran julia. If you launched Julia by clicking on an executable, then that folder will be…somewhere (I’m actually not sure where on Windows).

It sounds like what you want instead is to load a file relative to your .jl file (which is probably in a totally different folder from wherever you started Julia). To do that, you can use @__DIR__ to get the directory that the current file lives in. For example, you probably want to do: CSV.read(joinpath(@__dir__, "filename.csv"))



Yes, I’m trying to grab it from where the .jl file is located.
@__DIR__ worked

thank you