I want to get the filename of the latest file in a directory. latest is based on creation time.
Currently I stuck in sorting the 2-dimensional array. I do not know how I should sort it? I get the following error
ERROR: LoadError: MethodError: no method matching isless(::Array{Any,1}, ::Array{Any,1})
The 2-dimensional array looks like this:
Any[
Any[1.47913e9,"foo.csv"],
Any[1.47913e9,"bar.csv"],
Any[1.47913e9,"foobar.csv"]
]
dfolder = "C:\\Users\\Foo\\Downloads"
cd( dfolder )
dfiles = readdir( "." )
files=[]
#println( dfiles )
for file in dfiles
created = ctime( file )
push!(files, [created, file] )
end
println( files )
# sort the timestamp
sort!( files ) # This throws an error
# grab the newst file and display the filename
How do I display the newest file in the directory?
Try:
julia> sort!( files, by = e -> e[1])
The last item is the newest one:
julia> files[end]
2-element Array{Any,1}:
1.48061e9 ".whatever"
The filename is:
julia> files[end][2]
".whatever"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With