How to count files in current directory in Julia?

Written by Administrator on Thursday May 14, 2020

If you plan to count files in current directory in Julia, you can just run following code:

files_and_dirs = readdir(pwd())  # reading files and directory

function count()
    global num =0
    for i in files_and_dirs
        if isfile(i)
            num +=1
        end
    end
end

count()

println(num)

Example:

> juliea> julia number_of_files_in_current_directory.jl

Output:

19

Source:

count_files_in_current_directory_in_julia