Message Boards Message Boards

4 Replies
1 Total Likes
View groups...
Share this post:

Updating SetDirectory code written in version 5.2 to version 9

Posted 11 years ago
I have a notebook written by a past student with Mathematica version 5.2 which I am trying to update to run in Mathematica 9. This is what I am having trouble with:

<< Calculus`FourierTransform`
   Extract["FileName" /. NotebookInformation[EvaluationNotebook[]],
    {1}, FrontEnd`FileName

I believe I can remove "Calculus`FourierTransform`", as that package is now built-in, correct?
I tried replacing ToFileName with FileNameJoin but I still receive the error:

Extract::partd: "Part specification {1} is longer than depth of object.
SetDirectory::fstr: "File specification \!\(FileNameJoin[Extract[\"FileName\", {1}, FrontEnd`FileName]]\) is not a string of one or more characters.

Admittedly, I am a "beginner" at using Mathematica, and I hope these questions are not extremely simple.

Thanks for any help!
POSTED BY: Grant Kirkland
4 Replies
Good catch, that's much nicer!

@Grant, yes, I would think that the directory is being changed with the intent of reading (or writing) a file in that location.
POSTED BY: Ilian Gachevski
Or even more simple:
POSTED BY: Sander Huisman
Posted 11 years ago
Ok, thanks!
Now, if I understand it correctly, this part of code is setting the working directory to the directory of the notebook's file name?
So I'm assuming somewhere later in the code it will call another notebook from the same directory?
POSTED BY: Grant Kirkland
It should still work with ToFileName, but a simpler way to do the same in more recent versions is
The notebook does need to be saved to a file first.
POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract