2

I can show directory structure in emacs using M-! tree --dirfirst according to the answer here. But how to import a directory structure to emacs or org-mode heading ?

I want to have like:

- directory A
- directory AA
  - file A
- directory B
  - file B
- directory C
  - file C

Is there any workaround?

I tried using freeplane to import my folder structure, but always get wrong type argument p when importing to org file using org-freemind. using org-toggle-heading also does not help me.

thanks.

2 Answers 2

2

You can use org-fstree (install from MELPA or from here). It seems to do exactly what you want, it even makes each heading be a link to the corresponding file or folder.

To use it, just put a line

#+BEGIN_FSTREE: ~/path/to/folder

in your org file and type C-c C-c on it. This will create a copy of the directory tree mapped to nested org headlines.

A few caveats:

  1. Every time you do C-c C-c on the #+BEGIN_FSTREE line, the whole set of headings is replaced, including any text you may have typed under the headings. So, if you do want to add your own notes to the tree, you probably want to delete the #+BEGIN_FSTREE line after you have used it.

  2. It adds a lot of trailing blanks to each header line. You can remove these with M-x delete-trailing-whitespace

  3. I don't think it is strictly valid org syntax to nest headings inside a #+BEGIN ... #+END structure.

Here is an example of what it produces:

* Trying out org-fstree
#+BEGIN_FSTREE: fstree-test-folder :relative-links t

** |D| [[file:fstree-test-folder/directory-A][directory-A]]
** |D| [[file:fstree-test-folder/directory-AA][directory-AA]]
*** | | [[file:fstree-test-folder/directory-AA/file-A][file-A]]
** |D| [[file:fstree-test-folder/directory-B][directory-B]]
*** | | [[file:fstree-test-folder/directory-B/file-B][file-B]]
** |D| [[file:fstree-test-folder/directory-C][directory-C]]
*** | | [[file:fstree-test-folder/directory-C/file-C][file-C]]


#+END_FSTREE

Of course, in emacs it looks nicer than that since the links only show the description part by default.

5

Try C-u M-! and inserting the output from commands below that I adopted from another question / Answer

find . |sort|sed -E -e 's;(^.*[^/]/);\1 ;;s;([^/]*/);*;g;s/^\.$//'

That will give you a directory listing as headings, for example

* dir1
** file1
** file2
* dir2
** file1
* dir3

Select the region and convert headings to a lists using C-c -

- dir1
  - file1
  - file2
- dir2
  - file1
- dir3
3
  • 2
    This is clever, but it creates headlines rather than plain lists. I assume changing this example to use that format is trivial enough. Can you provide it as well, along with examples of how output of each of them looks like?
    – user12563
    Commented Dec 7, 2018 at 20:19
  • Ah yes. I was looking at the previous answer which gave headlines. As you rightly say the original question was for lists... Shall update when I get the opportunity.
    – alls0rts
    Commented Dec 10, 2018 at 11:06
  • As suggested, added example output and instruction on how to change Headings into a list using org rather than modifying sed command. Improved upon the command line too, adding sort and removing parent directory (.) within sed.
    – alls0rts
    Commented Dec 10, 2018 at 12:33

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.