Easy directory navigation within Mathematica

I was looking for a faster way to move working directories around in Mathematica and came up with this bash inspired series of commands to help.

This first one is very simple. pwd to see your directory.

pwd := Directory[]

By having the next one handy you can type “ls” shift+enter and you are presented with a series of buttons that show the directories and files in your working directory. Directories will be blue and files white. Clicking directories will switch your working directory and clicking files will open them. there is also an ‘up directory’ button marked by a double period.

ls:=Multicolumn[Join[Map[Button[ToString[#],SetDirectory[#];
SelectionMove[EvaluationNotebook[],Previous,Cell];
SelectionMove[EvaluationNotebook[],Previous,Cell];
SelectionEvaluate[EvaluationNotebook[]];,
Appearance->{"DialogBox","Pressed"}]&,
Prepend[Select[FileNames[],(DirectoryQ[#]&&!StringMatchQ[#,"."~~___])&],".."]],
Map[Button[ToString[#],SystemOpen[#]]&,Select[FileNames[],!(DirectoryQ[#]||StringMatchQ[#,"."~~___])&]]],5]//Quiet

If you want to see hidden items I have made the “lsa” command.

lsa:=Multicolumn[Join[Map[Button[ToString[#],SetDirectory[#];
SelectionMove[EvaluationNotebook[],Previous,Cell];
SelectionMove[EvaluationNotebook[],Previous,Cell];
SelectionEvaluate[EvaluationNotebook[]];,
Appearance->{"DialogBox","Pressed"}]&,
Prepend[Select[FileNames[],DirectoryQ[#]&],".."]],
Map[Button[ToString[#],SystemOpen[#]]&,Select[FileNames[],!(DirectoryQ[#])&]]],5]//Quiet

Depending on your display you may want to change the number of columns created. In this example it is set to 5. If no number is given it is automatic.