Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About stat function and reading the file path from a variable #1677

Closed
aborruso opened this issue Oct 5, 2024 · 4 comments
Closed

About stat function and reading the file path from a variable #1677

aborruso opened this issue Oct 5, 2024 · 4 comments

Comments

@aborruso
Copy link
Contributor

aborruso commented Oct 5, 2024

Hi,
if I run

echo 'file="tmp.txt"' | mlr --oxtab put '$file_info=stat($file)'

I get

file      "tmp.txt"
file_info (error)

If I hard code it

echo 'file="tmp.txt"' | mlr --oxtab put '$file_info=stat("tmp.txt")'

I get the right result

file              "tmp.txt"
file_info.name    tmp.txt
file_info.size    6
file_info.mode    0644
file_info.modtime 1728150479
file_info.isdir   false

The input of stat must be class=system, and I have a string. Is there any way to convert the value of a string variable to system?

Thank you

@johnkerl
Copy link
Owner

johnkerl commented Oct 6, 2024

The system bit is only a documentation category, not a runtime type ... no conversion issue.

Something else is up -- I'll look.

@johnkerl
Copy link
Owner

johnkerl commented Oct 6, 2024

@aborruso two things: one is that " isn't part of the filename; the other is that stat returns a map not a single value.

$ echo 'file=tmp.txt' | mlr --ojson put '$file_info=stat($file)'
[
{
  "file": "tmp.txt",
  "file_info": {
    "name": "tmp.txt",
    "size": 0,
    "mode": 0644,
    "modtime": 1728225438,
    "isdir": false
  }
}
]
$ echo 'file=tmp.txt' | mlr --oxtab put '$file_info=stat($file)'
file              tmp.txt
file_info.name    tmp.txt
file_info.size    0
file_info.mode    0644
file_info.modtime 1728225438
file_info.isdir   false

@aborruso
Copy link
Contributor Author

aborruso commented Oct 6, 2024

returns a map not a single value.

I know it, thank you. My stupid error is related to default mlr format: I thought it was necessary to put a string in double quotes.

Thank you

@aborruso aborruso closed this as completed Oct 6, 2024
@johnkerl
Copy link
Owner

johnkerl commented Oct 6, 2024

All good @aborruso ! It would be nice if someday DKVP could take quotes just as CSV does -- #266

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants