Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
3  
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
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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