Reading multiple txt files from a directory

Viewed 76

I am very new to Julia and I have a question regarding reading some files. I need to read 12500 .txt files from the same directory and save them all into 1 array but I'm having performance issues. Is there a fast way of doing this? My code takes around like 60 seconds which is way more than I can afford. Here is what I have:

function load_train(directory)
    data = []
    dir = joinpath("./aclImdb/train/",directory)
    for f in readdir(dir)
        s = read(joinpath(dir,f),String)
        push!(data,s)
    end
    data
end

trainPos = load_train("pos/")
0 Answers
Related