MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Comment about SetDirectory[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130878] Re: Comment about SetDirectory[]
  • From: W Craig Carter <ccarter at MIT.EDU>
  • Date: Thu, 23 May 2013 04:07:17 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <kn77kd$8ig$1@smc.vnet.net> <20130521040232.CCB9869F2@smc.vnet.net> <20130522061910.1D62A6A4D@smc.vnet.net>

I've seen one other case.
It was when the directory containing NotebookDirectory[] was deleted (by someone else on a shared disk).

For example,
temp.nb is written to ~/tmp/foo.
~/temp/foo is deleted with the notebook still open (a warning is dialog comes up.)
But:
NotebookDirectory[]
yields:
"/Users/ccarter/tmp/foo/"

Export[NotebookDirectory[] <> "file.m", "test"]
throws:
Export::nodir: "Directory \!\(\"/Users/ccarter/tmp/foo/\"\) does not exist"
Export::noopen: "Cannot open \!\(\"/Users/ccarter/tmp/foo/file.m\"\)."
and returns:
$Failed

This is a perverse example, but still possible. If something similar happened (disk dismounted, remounted) in the middle of Paul's writing a sequence of files, he would get a failure.



W Craig Carter
Professor of Materials Science, MIT



On May 22, 13, at 2:19 AM, John Fultz wrote:

> I've never heard of or seen Alexey's issue before.  However, it is the
> case that NotebookDirectory[] will return $Failed if you execute
> NotebookDirectory[]:
>
> * in a notebook which hasn't been saved to disk, and therefore doesn't
> have a notebook.
> * in an evaluation which wasn't directly triggered by a specific
> notebook, such as a ScheduledTask.
>
> John Fultz
> jfultz at wolfram.com
> User Interface Group
> Wolfram Research, Inc.
>
>
>
> On May 20, 2013, at 11:02 PM, "Alexey Popkov" <lehin.p at gmail.com> wrote:
>
>> Hi Paul,
>>
>> I would not recommend to use  the
>>
>> Export[NotebookDirectory[] <>  "TestResultTime.txt", mTimeDiff, "Table"]
>>
>> form if you are exporting many such files because NotebookDirectory[]
>> sometimes (approximately one time in 500 exports in one of my programs)
>> returns nothing and the file is exported to the default directory.
>>
>> As to your case I think it is possible that SetDirectory[] worked but
>> NotebookDirectory[] failed... I would recommend to check the output of
>> NotebookDirectory[] with StringLength.
>>
>> with best wishes,
>> Alexey
>>
>>
>>
>> "McHale, Paul"  wrote:kn77kd$8ig$1 at smc.vnet.net...
>>
>> I have often wondered whether to use:
>>
>> SetDirectory[NotebookDirectory[]]
>> Export["TestResultTime.txt", mTimeDiff, "Table"]
>>
>> or
>>
>> Export[NotebookDirectory[] <>  "TestResultTime.txt", mTimeDiff, "Table"]
>>
>> I have left Mathematica open for 2 days as it was running a very long test.
>> Maybe something became corrupted.  The first method did not work.  It
>> appears SetDirectory[] simply stopped functioning.  Personally, I think the
>> second method is better since it is atomic in nature.  It doesn't depend on
>> any stateful settings.
>>
>> Has anyone else had this issue?
>>
>> Thanks,
>>
>> Paul McHale  |  Electrical Engineer, Energetic Systems   |  Excelitas
>> Technologies Corp.
>>
>> Office: +1 937.865.3004   |  Fax: +1 937.865.5170
>> 1100 Vanguard Boulevard, Miamisburg, OH  45342-0312
>> Paul.McHale at Excelitas.com
>> www.excelitas.com
>>
>>
>
>


  • Prev by Date: Re: ListPlot skips first point
  • Next by Date: Re: ListPlot skips first point
  • Previous by thread: Re: Comment about SetDirectory[]
  • Next by thread: Re: Comment about SetDirectory[]