Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a folder exists

I am looking for a good way of checking whether a folder exists from within a Julia script. For now what I am doing is:

function dir_exists(dir)
  exists = true
  try
    readdir(dir)
  catch err
    exists = false
  end
  exists
end

but I was wonder if there's a way that doesn't rely on exception handling.

like image 601
Chris Rackauckas Avatar asked Nov 18 '18 02:11

Chris Rackauckas


People also ask

How do you check if a folder exists or not?

The Test-Path Cmdlet $Folder = 'C:\Windows' "Test to see if folder [$Folder] exists" if (Test-Path -Path $Folder) { "Path exists!" } else { "Path doesn't exist." } This is similar to the -d $filepath operator for IF statements in Bash. True is returned if $filepath exists, otherwise False is returned.

How do you check if a folder exists or not in Python?

isdir() method in Python is used to check whether the specified path is an existing directory or not. This method follows a symbolic link, which means if the specified path is a symbolic link pointing to a directory then the method will return True.

How do you check if a folder exists in a directory in Java?

File. exists() is used to check whether a file or a directory exists or not. This method returns true if the file or directory specified by the abstract path name exists and false if it does not exist.

How do I make sure a file exists?

To check if a file exists, you pass the file path to the exists() function from the os. path standard library. If the file exists, the exists() function returns True . Otherwise, it returns False .


1 Answers

The function is you are looking for is isdir.

like image 126
Warren Avatar answered Oct 26 '22 11:10

Warren