Files

  • You can use FileNames[ ] to get the list of files in your current directory. SetDirectory[ ] can be used to change your current directory, and ResetDirectory[ ] can be used to change it back to the default.

  • To write an expression to a file, you can use a command similar to expr >> file. The following example writes an expression to the file tmp.
    Expand[(a + b)^5] >> tmp

    .

  • To append an expression to a file, you can use a command similar to expr >>> file. This example appends another expression to the file tmp.
    Factor[x^6 - 1] >>> tmp

  • To receive the list of directories that Mathematica searches while attempting to find an external file, evaluate $Path. To add a directory to this list, try the following example.
    AppendTo[$Path, "directory"]


Return to the Mathematica tips index.