Making a Dataset that emulates `ls -tlra`?
Build your own
Here I create a Dataset
of files, taking advantage of the "Rules"
option for FileDate
. You can add your own information relevant for files or directories in the respective sections after DirectoryQ
. Just as a playful example I added FileHash
which may slows down things considerably.
lstlra[dir_] := Dataset[
<|(* For all files and directories *)
"FileName" -> FileNameTake[#],
"Type" -> FileType[#],
FileDate[#, "Rules"],
If[
DirectoryQ[#],
<|(* Directory only *)
|>,
<|(* Files only *)
"FileSize" -> FileSize[#],
"MD5-Hash" -> FileHash[#]
|>
]
|> & /@ FileNames[All, dir]
][SortBy["Modification"]]
Using File Information
After the answer by @swish, was very nice to learn about Information
applied to File
. Here I just change the Head
to and Association
(using Apply
@@
) to allow you to put your own stuff. Unfortunately it has too much information, more than you possible need.
lstlra2[dir_] := Dataset[
<|
Association @@ Information[File[#]],
If[
DirectoryQ[#],
<|(* Directory only *)
|>,
<|(* Files only *)
"MD5-Hash" -> FileHash[#]
|>
]
|> & /@ FileNames[All, dir]
][SortBy["LastModificationDate"]]
Minimal
lstlra3[d_]:=SortBy[Dataset[Information[File[#]][[1]]&/@FileNames[d]],"LastModificationDate"]
Try something like that
props = {"CreationDate", "UnixPermissionsString", "ByteCount"};
ls[dir_] :=
Dataset@FileSystemMap[
AssociationThread[props -> Information[File@#, props]] &, dir]
Why not interpreting the stdout of ls
itself
ls`tlra@path_:=ReadString["!ls -tlra "<>path] //
StringSplit /@ Rest@StringSplit[#,"\n"]& //
StringRiffle /@ Append[TakeList[#,{1,1,1,1,1,3}],#~Drop~8]& /@ #& //
AssociationThread[
{"Permissions" ,"ID","Owner","Group","Size","CreationDate","Name"}->#
]& /@ #& // Dataset