2
$\begingroup$

Here is one way to find the names of the files in one's home directory:

FileNames["*", "~"]
(* { "~/.account", "~/Applications", "~/.bash_sessions", ... } *)

Here is another way:

RunProcess[{"ls"}, ProcessDirectory -> "/Users/pillsy"]
(*  <|"ExitCode" -> 0, 
      "StandardOutput" -> "Applications
    Desktop...", "StandardError" -> ""|> *)

This is not a way to find the names of the files in one's home directory:

RunProcess[{"ls"}, ProcessDirectory -> "~"]
(* RunProcess::pnfd: Program ls not found.  Check Environment["PATH"]. 
   $Failed *) 

This is weird, both the lack of the expansion of the ~ and the completely mystifying error message. I'm not even sure how to conveniently expand that ~ to an absolute file name that works.

$\endgroup$
  • 3
    $\begingroup$ ExpandFileName will expand ~ $\endgroup$ – b3m2a1 Oct 17 '18 at 22:18
4
$\begingroup$

This is documented very clearly in the RunProcess documentation page...

Special symbols like ~ and * are not converted using shell expansion because RunProcess skips the shell:

If you want to access this programmatically, consider $HomeDirectory:

RunProcess[{"ls"}, ProcessDirectory -> $HomeDirectory]
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.