# Creating hyperlinks from a list of file names

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->{FrontEndFileName[{"Folder names"}, "FileName.nb",
CharacterEncoding -> "UTF-8"], None}]],
"Text"]


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.

-
You want the link to open the file it is referring to? Like: Button[#, NotebookOpen[FileNameJoin[{Directory[], #}]]] & /@ FileNames["*.nb"] –  Kuba Mar 27 at 13:55
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! –  Tom De Vries Mar 27 at 14:21
Please take a look at FileNames documentation. All is there. Have to go now, good luck. –  Kuba Mar 27 at 14:22
Thank you... this worked for me... Button[#, NotebookOpen[#]] & /@ FileNames[{"*.nb"}, {Directory[]}, Infinity] –  Tom De Vries Mar 27 at 14:24
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. –  Tom De Vries Mar 27 at 14:26

Hyperlink will work too, so for the record:

SetDirectory@NotebookDirectory[]
Composition[
Column,
Hyperlink[#, FileNameJoin[{Directory[], #}]] & /@ # &
]@FileNames["*.nb"]


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

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