Suppose I want to create a directory and a file in it....?

47 views
Skip to first unread message

Israel Hands

unread,
Oct 17, 2024, 5:53:45 AM10/17/24
to leo-editor
I use path to create the directory node - fine. However Leo will not create the directory in the file system until a file is created within the directory.
So I could create the directory and file in the file system but that isn't as neat as making Leo do the work.
So I create an @auto node in the as yet uncreated (in the file system) directory node and Leo complains when I try to save the outline because it can't save the @auto file because the  directory doesn't exist. 
If I use the write file from node command - it offers the system file requester which of course does not yet have the directory created in it.....

I feel I may be missing the bleeding obvious here!

Ta 

IH

Israel Hands

unread,
Oct 17, 2024, 5:56:55 AM10/17/24
to leo-editor
I've just noticed a similar ish question just a few lines below mine, sorry for not noticing that. If I enable the create missing directories will all my troubles be gone. I'm going to try now. 

Israel Hands

unread,
Oct 17, 2024, 6:05:32 AM10/17/24
to leo-editor
And indeed it does. First it labels the new directory with */Directory/* - saving the outline doesn't create it. But adding a file node with @file or @auto created both file and directory.  Is there a reason why creating directories directly in path without any file contents would be a bad thing?

ta

IH

Thomas Passin

unread,
Oct 17, 2024, 7:36:16 AM10/17/24
to leo-editor
Did you mean the setting @bool create_nonexistent_directories = True? I don't remember ever creating a directory without an @file at the end of it. You need to have a node for a file (it doesn't need to have any content) and save the outline before Leo will create the directory(s). Leo will create the entire tree of directories.  For example:

@path c:/temp/test-leo-directory/nested-1
    @clean leo-directory-test.txt

jkn

unread,
Oct 17, 2024, 7:40:04 AM10/17/24
to leo-editor
Interesting ... I was the person who raised the earlier topic I presume you are referring to. And I actually tried Thomas' settings suggestion ... and it didn't work for me.

Or at least, IIRC I had to use a particular combination of @path and @clean nodes to get it to work ... and in a way that I was not yet able to decide if there is leo bug, or in my understanding of how this should work.

I have a part-draft of a posting on this. I will try to finish it, but I think I had:

@path /path/to/new/directory
    @clean mynewfile.txt    # has '@all'
        node1   # with contents

and I was expecting this to create /path/to/new/directory/mynewfile.txt ... but it wasn't

Thomas Passin

unread,
Oct 17, 2024, 9:14:11 AM10/17/24
to leo-editor
Funny.  I just tried it before I posted and it did create the file and the inbetween directories at the end of the path. I'm on Windows and your path looks like Linux but I wouldn't think that would make a difference.  I don't know what the @all is supposed to do so I have no opinion as to whether it changed the behavior.

jkn

unread,
Oct 17, 2024, 9:29:30 AM10/17/24
to leo-editor
yes, I'm on Linux, but like you I would not expect that to make a difference. Now that the topic has been raised again I will re-experiment and post (I can also try under Windows).

I think the @all causes all the contents of the nodes underneath to be included in the @clean file. There are alternatives here (@others etc ...); I have'nt tried those for a while and will have to remind myslef. My short-cut thinking is that @all should help things, not hinder them...

    J^n

Edward K. Ream

unread,
Oct 17, 2024, 10:17:43 AM10/17/24
to leo-e...@googlegroups.com
On Thu, Oct 17, 2024 at 8:29 AM jkn <jkn...@nicorp.f9.co.uk> wrote:

yes, I'm on Linux, but like you I would not expect that to make a difference. Now that the topic has been raised again I will re-experiment and post (I can also try under Windows).

Looks like a bug in g.makeAllNonExistentDirectories. See #4107.

Edward

Edward K. Ream

unread,
Oct 17, 2024, 10:38:13 AM10/17/24
to leo-editor
On Thursday, October 17, 2024 at 9:17:43 AM UTC-5 Edward K. Ream wrote:

Looks like a bug in g.makeAllNonExistentDirectories. See #4107.

It looks like this method works about as well as can be expected, and it would not be easy to make it more robust. I am going to close this issue. Feel free to reopen only if:

- @bool create-nonexistent-directories = True
- @path contains a path to a directory (not a file)
- @path is still not working as you expect.

Edward

jkn

unread,
Oct 17, 2024, 10:39:46 AM10/17/24
to leo-editor
Ah, interesting. I will post these results (on Windows, FWIW) in any case.

Capture.PNG

This is a test file (C:/Users/nicoll/Seafile/at_files/@leo/test1.leo) I created earlier

My intention was to create two directories and files:
   C:/Users/nicoll/Seafile/at_files/@leo/test1.leo/test_subdir1/subfile1.txt
    C:/Users/nicoll/Seafile/at_files/@leo/test1.leo/test_subdir2/subfile2.txt

you can see that when reading the file, the subdirectories were not found.

I then edited the body of the nodes nodeA1 and node3b. A write then caused the subdirectories and files to be created.

Both the previous run of this, and this run, had @bool create_nonexistent_directories = True


    J^n



Edward K. Ream

unread,
Oct 17, 2024, 10:59:08 AM10/17/24
to leo-e...@googlegroups.com
On Thu, Oct 17, 2024 at 9:39 AM jkn <jkn...@nicorp.f9.co.uk> wrote:
Ah, interesting. I will post these results (on Windows, FWIW) in any case.

Capture.PNG

This is a test file (C:/Users/nicoll/Seafile/at_files/@leo/test1.leo) I created earlier

My intention was to create two directories and files:
   C:/Users/nicoll/Seafile/at_files/@leo/test1.leo/test_subdir1/subfile1.txt
    C:/Users/nicoll/Seafile/at_files/@leo/test1.leo/test_subdir2/subfile2.txt

you can see that when reading the file, the subdirectories were not found.

Hmm. This could be hard to fix. I certainly will not consider fixing it for the upcoming release.

Edward

Thomas Passin

unread,
Oct 17, 2024, 12:02:05 PM10/17/24
to leo-editor
I would be very suspicious of that "@leo" directory name. Would you repeat your tests but with a normal directory name (i.e., one without an "@" character)?

Edward K. Ream

unread,
Oct 17, 2024, 12:32:29 PM10/17/24
to leo-e...@googlegroups.com
On Thu, Oct 17, 2024 at 11:02 AM Thomas Passin <tbp1...@gmail.com> wrote:

> I would be very suspicious of that "@leo" directory name.

I am suspicious too.


> Would you repeat your tests but with a normal directory name (i.e., one without an "@" character)?

I wouldn't bother, because...


> you can see that when reading the file, the subdirectories were not found.

Presumably that's because the directories didn't exist.

> I then edited the body of the nodes nodeA1 and node3b. A write then caused the subdirectories and files to be created.

So, as expected, Leo created the directories when writing.

Imo, Leo should not create directories when reading, because there will be nothing to read!

Let's move on, please.

Edward

jkn

unread,
Oct 17, 2024, 1:06:41 PM10/17/24
to leo-editor
Please, understand the point I was trying to make in the imperfect example above. This was a 're-load' of an previously-created .leo file. The directories/files had failed to be previously created (despite having create-non-existent-directories = True at that time).

I will try without the @-directory name, but I don't see why it should be a problem. I happen to use this convention for certain file locations (including all my 'standard' leo files) and have zero issues with it. In what way is this a more 'special' filename character than 'space', for instance?

As a slight aside, if I had not edited the node bodies, would you have expected the directories to then be created upon a write? There seems to be some sort of cache logic going on, but I am a bit unsure.

I will re-run the layout I have above but (a) with a new outline, (b) with a path not containing '@'.

I think you are confirming that my understanding of what the expected behaviour should be is correct, so that is useful.

Thanks, J^n

Edward K. Ream

unread,
Oct 17, 2024, 1:35:06 PM10/17/24
to leo-e...@googlegroups.com
On Thu, Oct 17, 2024 at 12:06 PM jkn <jkn...@nicorp.f9.co.uk> wrote:

Please, understand the point I was trying to make in the imperfect example above. This was a 're-load' of an previously-created .leo file. The directories/files had failed to be previously created (despite having create-non-existent-directories = True at that time).

That failure to create the files is the culprit.

Edward

Thomas Passin

unread,
Oct 17, 2024, 5:19:09 PM10/17/24
to leo-editor
On Thursday, October 17, 2024 at 1:06:41 PM UTC-4 jkn wrote:

As a slight aside, if I had not edited the node bodies, would you have expected the directories to then be created upon a write? There seems to be some sort of cache logic going on, but I am a bit unsure.

One thing I know.  You have to save the outline to have the new @file saved.  At that time the directories should get created if they don't already exist. Nothing is going to get created before the file is saved the first time.  It doesn't need to have content, just to be saved. If you create an @path node but no file at the end of that path, Leo will see nothing to save and those directories aren't going to be created. I've just tested all these statements, BTW.

If you created @path nodes and @file nodes in them, but "Revert To Saved"  before saving the outline, Leo will reload the outline as it was and will not create those directories and @files - since you had not saved them first.

This behavior makes sense to me.  When you save an outline, Leo looks for any and all at-files (or probably it's just all dirty at-file nodes) and saves them.  If it notices that there is one with non-existent directories, it knows it has to create them before that file can be saved.

jkn

unread,
Oct 18, 2024, 3:31:32 AM10/18/24
to leo-editor
well, that was my point. I see no reason for that to have occurred.

Still experimenting...

J^n
 
Edward
Reply all
Reply to author
Forward
0 new messages