1
$\begingroup$

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}]],
    "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.

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

1 Answer 1

2
$\begingroup$

Hyperlink will work too, so for the record:

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

enter image description here

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

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

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.