Suppose I use FileNames to get a list of file names.

I know that it's possible to make a hyperlink using this kind of pattern....

Cell[TextData[ButtonBox["Link Label", BaseStyle->"Hyperlink",
               ButtonData->{FrontEnd`FileName[{"Folder names"}, "FileName.nb",  
                            CharacterEncoding -> "UTF-8"], None}]],

I would appreciate help with taking a list of file names and writing them as working hyperlinks in a specified notebook.

To be clear, I'd like the hyperlink to open the file referred to by the hyperlink.

I tried taking a file path, splitting it to get the parts, using that for the folder structure and the file name, but couldn't get it to work.

  • 3
    $\begingroup$ You want the link to open the file it is referring to? Like: Button[#, NotebookOpen[FileNameJoin[{Directory[], #}]]] & /@ FileNames["*.nb"] $\endgroup$ – Kuba Mar 27 '14 at 13:55
  • $\begingroup$ Thank you, wow, that already looks promising. I tried that, how would I modify so it looks into "sub-folders". The above command is fantastic, but only finds files in the current directory. I appreciate your help! $\endgroup$ – Tom De Vries Mar 27 '14 at 14:21
  • $\begingroup$ Please take a look at FileNames documentation. All is there. Have to go now, good luck. $\endgroup$ – Kuba Mar 27 '14 at 14:22
  • $\begingroup$ Thank you... this worked for me... Button[#, NotebookOpen[#]] & /@ FileNames[{"*.nb"}, {Directory[]}, Infinity] $\endgroup$ – Tom De Vries Mar 27 '14 at 14:24
  • $\begingroup$ Right, that was "theoretical", I wouldn't have folders more than 2 or 3 levels deep... I was just testing to see if it worked. Thanks for your comment. $\endgroup$ – Tom De Vries Mar 27 '14 at 14:26

Hyperlink will work too, so for the record:

  Hyperlink[#, FileNameJoin[{Directory[], #}]] & /@ # &

enter image description here

Of course you can play with FileNames and/or SetDirectory to adjust search to your needs.

  • $\begingroup$ Thanks! and thanks for adding that so I could give you credit for an answer! $\endgroup$ – Tom De Vries Mar 29 '14 at 12:27
  • $\begingroup$ @TomDeVries I'm glad I could help :) $\endgroup$ – Kuba Mar 29 '14 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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