排序二维数组时出现问题

时间:2016-12-01 15:04:39

标签: arrays sorting julia

我想获取目录中最新文件的文件名。最新的是基于创作时间。

目前我坚持对二维数组进行排序。我不知道应该怎么排序呢?我收到以下错误

  

错误:LoadError:MethodError:没有方法匹配无效(:: Array {Any,1},:: Array {Any,1})

二维数组如下所示:

Any[
    Any[1.47913e9,"foo.csv"],
    Any[1.47913e9,"bar.csv"],
    Any[1.47913e9,"foobar.csv"]
]

newestfile.jl

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

如何在目录中显示最新文件?

1 个答案:

答案 0 :(得分:3)

尝试:

julia> sort!( files, by = e -> e[1])

最后一项是最新项目:

julia> files[end]
2-element Array{Any,1}:
1.48061e9 ".whatever"

文件名为:

julia> files[end][2]
".whatever"
相关问题