2
$\begingroup$

Abstract: when managing hundreds of notebook files without a git system (version management) it would be very convenient to automatically show its own filename and last modified date at the top when opened. Can this be done?

About the Code: Here is my very bad attempt at doing this that fails miserably.

FileDate["D:\Google Drive\projects\experiments\data\statistics.nb"]
$\endgroup$
2

2 Answers 2

7
$\begingroup$

Here's one approach using a docked cell:

SetOptions[EvaluationNotebook[], 
 DockedCells -> 
  Cell[BoxData[
    ToBoxes[Dynamic[
      Column[{NotebookFileName[], 
        DateString[
         Information[EvaluationNotebook[], "FileModificationTime"]]}],
       UpdateInterval -> 60]]]]]

enter image description here

The content updates once a minute. You could set this globally by using $FrontEnd (survives through restarting the frontend) or $FrontEndSession (cleared by restarting the frontend), but you'll want to add some logic for what to display in a new notebook that has never been saved to disk (and maybe also notebooks that live in the cloud.)

$\endgroup$
0
$\begingroup$

After digging through documentation I have found that there is a way and it's very easy. I packaged it into a nice little function for giving current user, current open file, and date modified and as a bonus I even included a function to clear memory.

Here ya go:

Clear["Global`*"]
systemInfo[] := Column[{Row[{Style["User: ", Bold], $Username}],
   Row[{Style["Filename: ", Bold], FileNameTake[NotebookFileName[]]}],
   Row[{Style["Last Modified: ", Bold], 
     DateString[FileDate[NotebookFileName[]]]}]}
  ]
clearMemory[] := {MemoryInUse[], Unprotect[In, Out], Clear[In, Out], 
   Protect[In, Out], MemoryInUse[]};
systemInfo[]
clearMemory[]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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