Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking file existence in Julia

Tags:

julia

Is there a simple way in Julia to check whether a file in the current working directory exists (something like test = os.path.isfile("foo.txt") in Python or inquire(file = "foo.txt", exist = test) in Fortran)?

like image 564
Benjamin Avatar asked Mar 13 '16 21:03

Benjamin


People also ask

How do you create a file in Julia?

Writing To a File In Julia In order to write in a file, we need to open the file in write mode by passing “w” as a parameter. Now to write to a file in Julia we use write(fileobject, string) method. It takes two arguments, first is the file object and the second is the String provided.

What is the file extension for Julia?

jl , write include("file. jl") . You can pass additional arguments to Julia, and to your program script. jl .

How do I change my working directory in Julia?

The command to change working directory is cd(dir::AbstractString=homedir()).


1 Answers

Julia has the isfile() function to test for a regular file:

julia> isfile("foo.txt") false  shell> touch foo.txt  julia> isfile("foo.txt") true 

As the documentation:

Returns true if path (the parameter) is a regular file, false otherwise.

like image 58
Gomiero Avatar answered Sep 24 '22 20:09

Gomiero