({{, (RefLink[NotebookFileName, paclet:ref/NotebookFileName])[]
gives the file name of the current evaluation notebook. }, {, (RefLink[NotebookFileName, paclet:ref/NotebookFileName])[nb]
gives the file name for the notebook specified by nb. }})

OpenersNotesSection(Spacer1)Details

(RefLink[NotebookFileName, paclet:ref/NotebookFileName]) returns the absolute file name for the notebook as a string.

(RefLink[NotebookFileName, paclet:ref/NotebookFileName]) gives (RefLink[$Failed, paclet:ref/$Failed]) if the specified notebook has never been saved as a file.

The file name given by (RefLink[NotebookFileName, paclet:ref/NotebookFileName]) is on the filesystem of the computer on which the notebook front end is being run.

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Create a notebook, save it in a file, and then open it:

NotebookSave[Notebook[{Cell["Hello","Text"]}],FileNameJoin[{$TemporaryDirectory,"Hello.nb"}]]

nb=NotebookOpen[FileNameJoin[{$TemporaryDirectory,"Hello.nb"}]];

Find the file name for the notebook:

NotebookFileName[nb]

Close the notebook and delete the file:

NotebookClose[nb]

DeleteFile[FileNameJoin[{$TemporaryDirectory,"Hello.nb"}]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NotebookDirectory, paclet:ref/NotebookDirectory])  ▪  (RefLink[$Input, paclet:ref/$Input])  ▪  (RefLink[$InputFileName, paclet:ref/$InputFileName])  ▪  (RefLink[FileNameSplit, paclet:ref/FileNameSplit])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Operations on File Names, paclet:guide/OperationsOnFileNames])}, {▪(RefLinkPlain[Low-Level Notebook Programming, paclet:guide/LowLevelNotebookProgramming])}})}})