Making a Dataset that emulates `ls -tlra`?Doubts on scripting: error messages when trying to run and how to process lots of filesGet the last line from each of a large number of files, transform them, and write all results to a single new fileUnable to import .m file in WSTPHow to workaround failures with Unicode filepaths?Convert variable name to filenameHow to read this dataset with .dat and .r64 files?Automatically making a path to the users directoryCleanest way to copy part of one directory to anotherBetter random (unique) file nameUsing Open with a filename that contains “:”
I have found a mistake on someone's code published online: what is the protocol?
Could a US citizen born through "birth tourism" become President?
How long were the Apollo astronauts allowed to breathe 100% oxygen at 1 atmosphere continuously?
Making a Dataset that emulates `ls -tlra`?
Why do space operations use "nominal" to mean "working correctly"?
Should I have shared a document with a former employee?
Should I have one hand on the throttle during engine ignition?
Which GPUs to get for Mathematical Optimization (if any)?
When will the last unambiguous evidence of mankind disappear?
Why is an object not defined as identity morphism?
How was Luke's prosthetic hand in Episode V filmed?
How to interpret a promising preprint that was never published in peer-review?
Do medium format lenses have a crop factor?
Did Hitler say this quote about homeschooling?
What is this green alien supposed to be on the American covers of the "Hitchhiker's Guide to the Galaxy"?
Why can't I hear fret buzz through the amp?
Does Holy Water deal damage on a failed attack roll?
Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation
Do pedestrians imitate auto traffic?
Why don't humans perceive waves as twice the frequency they are?
Why do jet engines sound louder on the ground than inside the aircraft?
What is the name for the average of the largest and the smallest values in a given data set?
We get more abuse than anyone else
What would be the safest way to drop thousands of small, hard objects from a typical, high wing, GA airplane?
Making a Dataset that emulates `ls -tlra`?
Doubts on scripting: error messages when trying to run and how to process lots of filesGet the last line from each of a large number of files, transform them, and write all results to a single new fileUnable to import .m file in WSTPHow to workaround failures with Unicode filepaths?Convert variable name to filenameHow to read this dataset with .dat and .r64 files?Automatically making a path to the users directoryCleanest way to copy part of one directory to anotherBetter random (unique) file nameUsing Open with a filename that contains “:”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
When we ls -tlra
in bash, we get filename information, size of files, date last modified, etc. Is there a way to create a Mathematica function which generates a Dataset of all of this information?
Some key functions here: FileNames[]
, FileDate[]
, FileSize[]
. I'm not sure how to get information about file permissions, but that is less important.
files-and-directories
$endgroup$
add a comment |
$begingroup$
When we ls -tlra
in bash, we get filename information, size of files, date last modified, etc. Is there a way to create a Mathematica function which generates a Dataset of all of this information?
Some key functions here: FileNames[]
, FileDate[]
, FileSize[]
. I'm not sure how to get information about file permissions, but that is less important.
files-and-directories
$endgroup$
add a comment |
$begingroup$
When we ls -tlra
in bash, we get filename information, size of files, date last modified, etc. Is there a way to create a Mathematica function which generates a Dataset of all of this information?
Some key functions here: FileNames[]
, FileDate[]
, FileSize[]
. I'm not sure how to get information about file permissions, but that is less important.
files-and-directories
$endgroup$
When we ls -tlra
in bash, we get filename information, size of files, date last modified, etc. Is there a way to create a Mathematica function which generates a Dataset of all of this information?
Some key functions here: FileNames[]
, FileDate[]
, FileSize[]
. I'm not sure how to get information about file permissions, but that is less important.
files-and-directories
files-and-directories
asked 10 hours ago
GeorgeGeorge
4931 silver badge9 bronze badges
4931 silver badge9 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
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"]]
$endgroup$
1
$begingroup$
Is there a way to have the final results sorted by date modified (this is also the behavior ofls -tlra
I believe).
$endgroup$
– George
9 hours ago
$begingroup$
@George Oh, forgot about that, see last edit. I added[SortBy["Modification"]]
andSortBy["LastModificationDate"]
depending the function.
$endgroup$
– rhermans
9 hours ago
add a comment |
$begingroup$
Try something like that
props = "CreationDate", "UnixPermissionsString", "ByteCount";
ls[dir_] :=
Dataset@FileSystemMap[
AssociationThread[props -> Information[File@#, props]] &, dir]
$endgroup$
1
$begingroup$
Nice one! (+1) Thanks for introducing me toInformation
applied toFile
.
$endgroup$
– rhermans
9 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202399%2fmaking-a-dataset-that-emulates-ls-tlra%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
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"]]
$endgroup$
1
$begingroup$
Is there a way to have the final results sorted by date modified (this is also the behavior ofls -tlra
I believe).
$endgroup$
– George
9 hours ago
$begingroup$
@George Oh, forgot about that, see last edit. I added[SortBy["Modification"]]
andSortBy["LastModificationDate"]
depending the function.
$endgroup$
– rhermans
9 hours ago
add a comment |
$begingroup$
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"]]
$endgroup$
1
$begingroup$
Is there a way to have the final results sorted by date modified (this is also the behavior ofls -tlra
I believe).
$endgroup$
– George
9 hours ago
$begingroup$
@George Oh, forgot about that, see last edit. I added[SortBy["Modification"]]
andSortBy["LastModificationDate"]
depending the function.
$endgroup$
– rhermans
9 hours ago
add a comment |
$begingroup$
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"]]
$endgroup$
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"]]
edited 9 hours ago
answered 9 hours ago
rhermansrhermans
23.3k4 gold badges42 silver badges107 bronze badges
23.3k4 gold badges42 silver badges107 bronze badges
1
$begingroup$
Is there a way to have the final results sorted by date modified (this is also the behavior ofls -tlra
I believe).
$endgroup$
– George
9 hours ago
$begingroup$
@George Oh, forgot about that, see last edit. I added[SortBy["Modification"]]
andSortBy["LastModificationDate"]
depending the function.
$endgroup$
– rhermans
9 hours ago
add a comment |
1
$begingroup$
Is there a way to have the final results sorted by date modified (this is also the behavior ofls -tlra
I believe).
$endgroup$
– George
9 hours ago
$begingroup$
@George Oh, forgot about that, see last edit. I added[SortBy["Modification"]]
andSortBy["LastModificationDate"]
depending the function.
$endgroup$
– rhermans
9 hours ago
1
1
$begingroup$
Is there a way to have the final results sorted by date modified (this is also the behavior of
ls -tlra
I believe).$endgroup$
– George
9 hours ago
$begingroup$
Is there a way to have the final results sorted by date modified (this is also the behavior of
ls -tlra
I believe).$endgroup$
– George
9 hours ago
$begingroup$
@George Oh, forgot about that, see last edit. I added
[SortBy["Modification"]]
and SortBy["LastModificationDate"]
depending the function.$endgroup$
– rhermans
9 hours ago
$begingroup$
@George Oh, forgot about that, see last edit. I added
[SortBy["Modification"]]
and SortBy["LastModificationDate"]
depending the function.$endgroup$
– rhermans
9 hours ago
add a comment |
$begingroup$
Try something like that
props = "CreationDate", "UnixPermissionsString", "ByteCount";
ls[dir_] :=
Dataset@FileSystemMap[
AssociationThread[props -> Information[File@#, props]] &, dir]
$endgroup$
1
$begingroup$
Nice one! (+1) Thanks for introducing me toInformation
applied toFile
.
$endgroup$
– rhermans
9 hours ago
add a comment |
$begingroup$
Try something like that
props = "CreationDate", "UnixPermissionsString", "ByteCount";
ls[dir_] :=
Dataset@FileSystemMap[
AssociationThread[props -> Information[File@#, props]] &, dir]
$endgroup$
1
$begingroup$
Nice one! (+1) Thanks for introducing me toInformation
applied toFile
.
$endgroup$
– rhermans
9 hours ago
add a comment |
$begingroup$
Try something like that
props = "CreationDate", "UnixPermissionsString", "ByteCount";
ls[dir_] :=
Dataset@FileSystemMap[
AssociationThread[props -> Information[File@#, props]] &, dir]
$endgroup$
Try something like that
props = "CreationDate", "UnixPermissionsString", "ByteCount";
ls[dir_] :=
Dataset@FileSystemMap[
AssociationThread[props -> Information[File@#, props]] &, dir]
answered 10 hours ago
swishswish
4,38615 silver badges37 bronze badges
4,38615 silver badges37 bronze badges
1
$begingroup$
Nice one! (+1) Thanks for introducing me toInformation
applied toFile
.
$endgroup$
– rhermans
9 hours ago
add a comment |
1
$begingroup$
Nice one! (+1) Thanks for introducing me toInformation
applied toFile
.
$endgroup$
– rhermans
9 hours ago
1
1
$begingroup$
Nice one! (+1) Thanks for introducing me to
Information
applied to File
.$endgroup$
– rhermans
9 hours ago
$begingroup$
Nice one! (+1) Thanks for introducing me to
Information
applied to File
.$endgroup$
– rhermans
9 hours ago
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202399%2fmaking-a-dataset-that-emulates-ls-tlra%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown