Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Bare Bones Backup Button

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111514] Re: Bare Bones Backup Button
  • From: David Reiss <dbreiss at gmail.com>
  • Date: Tue, 3 Aug 2010 06:43:37 -0400 (EDT)
  • References: <i368lp$r56$1@smc.vnet.net>

I think that the best way is to  simply check to see if the directory
exists using FileType[dir]===Directory (pre version 7)   or
DirectoryQ[dir] (version 7 or above).

(by the way, as you know, there is a backup facility in
http://scientificarts.com/worklife).

--David

On Aug 2, 7:03 am, Murray Eisenberg <mur... at math.umass.edu> wrote:
> An exchange reported in  between DrMajorBob and Selwyn Hollis
> culminated, in essence, in the code below for creating a saveable
> palette with a button to back up the InputNotebook.
>
> If the target directory for the backup (fixed in the code that creates
> the palette) already exists, then each time I click the button, I get an
> unwanted message
>
>    CreateDirectory::filex : ... already exists
>
> in the Messages window.
>
> What is the best way to modify the code so as avoid that message? I can
> think of two methods:
>
> (1) Include a separate test as to whether that directory already exists
> and, if so, by-pass the CreateDirectory phase; or
>
> (2) Somehow trap the CreateDirectory so as to eliminate the message.
>
> For Method (1), how does one tell whether a directory exists? I don't
> find a single function that does it. All I can see is to use first
> FileExistsQ to see if there's some file with the target directory's name
> and second, if the file exists, FileType to check that it's a directory.
>   That seems to be getting unduly complicated.
>
> Method (2) in principle seems simpler, and perhaps wrapping Quiet around
> the entire body of the Module (which is an extended If expression) would
> do the trick. But this would also suppress other messages that one might
> want to see, such as when the directory does not already exist but for
> some reason cannot be created; or that the directory exists but for some
> reason is not writable; etc.
>
> Suggestions?
>
> The code:
>
> CreateDocument[PaletteNotebook[Button["Bare Bones Backup",
>    Module[{filename,thisnb=InputNotebook[]},
>      If[thisnb=!=$Failed,
>         CreateDirectory[
>           ToFileName[{"e:/backups","MmaBareBones"}]];
>         filename=
>           StringJoin[
>             StringReplace[(WindowTitle/.AbsoluteOptions[thisn=
b]),
>               s_~~".nb"->s],"_",
>           StringJoin[ToString/@ Round/@ Rest[Date[]]],".nb"];
>         Export[
>           ToFileName[{"e:/backups","MmaBareBones"},filename],
>           DeleteCases[NotebookGet[thisnb],Cell[_,"Output",___],
>             Infinity]]]]],
>      Saveable->True]]
>
> --
> Murray Eisenberg                     mur... at math.umas=
s.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower      phone 413 549-1020 (H)
> University of Massachusetts                413 545-2859 (=
W)
> 710 North Pleasant Street            fax   413 545-1801
> Amherst, MA 01003-9305



  • Prev by Date: Re: A distribution problem using Mathematica
  • Next by Date: Re: ReplaceAll and ReplaceRepeated Strange Behavior
  • Previous by thread: Re: Bare Bones Backup Button
  • Next by thread: Re: Bare Bones Backup Button