Recursive folder creation

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Recursive folder creation

** Clarence P Martin ** via use-livecode
Attempts to create a subfolder below a folder that does not exists fail.

Where folder "nature" exists but folder "2017" does not, attempt to create folder "birds" below 2017  fail.

put specialFolderPath["Documents"] into tDF

#  "/media/audio/nature" #these folders exist
# /2017/birds"   # does not, yet.

put tDF & "/media/audio/nature/2017/birds" into tFolder

create folder tFolder
put the result

"can't create that directory"

OK so… if I remove the "/2017" from my test path string and run it… we get the folder created as expected, where the new folder is a subfolder of an already existing folder.

Ok so this all makes perfect sense, but before I go looping thru the path to check for existence of each folder in the hierarchy and creating it if I does not exist. I was wondering

1) am I missing something or is this just expected behavior

and

2) Does it make sense to ask for an enhancement request for the engine to recursively create folders for a path where itemdel "/" and items -1,-2,-3 (sub folders) do not exist?

on unix

cp --parents 'a/b/c'  'audio/nature'

# will do this job… and you get

audio/nature/a/b/c

on disk

so I suppose one could resort to shell but this is not available on mobile. Hence the engine enhancement request.

meanwhile back to writing a repeat loop to check on sub folder and create on the fly. From all I'm seeing the CPUs  of all phones of all grades hardly have an issue, bencemark wise with this kind of processing… all the "trouble" is at the rendering layer.  From beta test reports where some rather snakey code is executed equally fast on all phones, but not anything having to do with pixels…e.g. fetch, process and assemble data to push to 100 sub-groups of a big scrolling group… wink of an eye… actually build and layout the sub-groups in the UI and display: slow as molasses on android.

BR



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
Well, lazy types like me would just create the folder "2017" followed
by the folder "birds".

Richmond.

On 8/7/17 8:57 pm, Sannyasin Brahmanathaswami via use-livecode wrote:

> Attempts to create a subfolder below a folder that does not exists fail.
>
> Where folder "nature" exists but folder "2017" does not, attempt to create folder "birds" below 2017  fail.
>
> put specialFolderPath["Documents"] into tDF
>
> #  "/media/audio/nature" #these folders exist
> # /2017/birds"   # does not, yet.
>
> put tDF & "/media/audio/nature/2017/birds" into tFolder
>
> create folder tFolder
> put the result
>
> "can't create that directory"
>
> OK so… if I remove the "/2017" from my test path string and run it… we get the folder created as expected, where the new folder is a subfolder of an already existing folder.
>
> Ok so this all makes perfect sense, but before I go looping thru the path to check for existence of each folder in the hierarchy and creating it if I does not exist. I was wondering
>
> 1) am I missing something or is this just expected behavior
>
> and
>
> 2) Does it make sense to ask for an enhancement request for the engine to recursively create folders for a path where itemdel "/" and items -1,-2,-3 (sub folders) do not exist?
>
> on unix
>
> cp --parents 'a/b/c'  'audio/nature'
>
> # will do this job… and you get
>
> audio/nature/a/b/c
>
> on disk
>
> so I suppose one could resort to shell but this is not available on mobile. Hence the engine enhancement request.
>
> meanwhile back to writing a repeat loop to check on sub folder and create on the fly. From all I'm seeing the CPUs  of all phones of all grades hardly have an issue, bencemark wise with this kind of processing… all the "trouble" is at the rendering layer.  From beta test reports where some rather snakey code is executed equally fast on all phones, but not anything having to do with pixels…e.g. fetch, process and assemble data to push to 100 sub-groups of a big scrolling group… wink of an eye… actually build and layout the sub-groups in the UI and display: slow as molasses on android.
>
> BR
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
You can only create one folder at a time. You can not create nested folders in one go.

So you need to do like this

put tDF & "/media/audio/nature/2017/" into tFolder
create folder tFolder
put “birds” after tFolder
create folder tFolder

Regards
Tore

>
> 7. aug. 2017 kl. 19:57 skrev Sannyasin Brahmanathaswami via use-livecode <[hidden email]>:
>
> Attempts to create a subfolder below a folder that does not exists fail.
>
> Where folder "nature" exists but folder "2017" does not, attempt to create folder "birds" below 2017  fail.
>
> put specialFolderPath["Documents"] into tDF
>
> #  "/media/audio/nature" #these folders exist
> # /2017/birds"   # does not, yet.
>
> put tDF & "/media/audio/nature/2017/birds" into tFolder
>
> create folder tFolder
> put the result
>
> "can't create that directory"
>
> OK so… if I remove the "/2017" from my test path string and run it… we get the folder created as expected, where the new folder is a subfolder of an already existing folder.
>
> Ok so this all makes perfect sense, but before I go looping thru the path to check for existence of each folder in the hierarchy and creating it if I does not exist. I was wondering
>
> 1) am I missing something or is this just expected behavior
>
> and
>
> 2) Does it make sense to ask for an enhancement request for the engine to recursively create folders for a path where itemdel "/" and items -1,-2,-3 (sub folders) do not exist?
>
> on unix
>
> cp --parents 'a/b/c'  'audio/nature'
>
> # will do this job… and you get
>
> audio/nature/a/b/c
>
> on disk
>
> so I suppose one could resort to shell but this is not available on mobile. Hence the engine enhancement request.
>
> meanwhile back to writing a repeat loop to check on sub folder and create on the fly. From all I'm seeing the CPUs  of all phones of all grades hardly have an issue, bencemark wise with this kind of processing… all the "trouble" is at the rendering layer.  From beta test reports where some rather snakey code is executed equally fast on all phones, but not anything having to do with pixels…e.g. fetch, process and assemble data to push to 100 sub-groups of a big scrolling group… wink of an eye… actually build and layout the sub-groups in the UI and display: slow as molasses on android.
>
> BR
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
+1

Tore

> 7. aug. 2017 kl. 19:57 skrev Sannyasin Brahmanathaswami via use-livecode <[hidden email] <mailto:[hidden email]>>:
>
> 2) Does it make sense to ask for an enhancement request for the engine to recursively create folders for a path where itemdel "/" and items -1,-2,-3 (sub folders) do not exist?

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
 
 

 Check out _revSBEnsureFolder in revSBLibrary for example code that does this.
 

 
 

 
 
>  
> On Aug 7, 2017 at 12:57 PM,  <Sannyasin Brahmanathaswami via use-livecode (mailto:[hidden email])>  wrote:
>  
>  
>  
>  Attempts to create a subfolder below a folder that does not exists fail. Where folder "nature" exists but folder "2017" does not, attempt to create folder "birds" below 2017 fail. put specialFolderPath["Documents"] into tDF # "/media/audio/nature" #these folders exist # /2017/birds" # does not, yet. put tDF  &  "/media/audio/nature/2017/birds" into tFolder create folder tFolder put the result "can't create that directory" OK so… if I remove the "/2017" from my test path string and run it… we get the folder created as expected, where the new folder is a subfolder of an already existing folder. Ok so this all makes perfect sense, but before I go looping thru the path to check for existence of each folder in the hierarchy and creating it if I does not exist. I was wondering 1) am I missing something or is this just expected behavior and 2) Does it make sense to ask for an enhancement request for the engine to recursively create folders for a path where itemdel "/" and items -1,-2,-3 (sub folders) do not exist? on unix cp --parents 'a/b/c' 'audio/nature' # will do this job… and you get audio/nature/a/b/c on disk so I suppose one could resort to shell but this is not available on mobile. Hence the engine enhancement request. meanwhile back to writing a repeat loop to check on  sub folder and create on the fly. From all I'm seeing the CPUs of all phones of all grades hardly have an issue, bencemark wise with this kind of processing… all the "trouble" is at the rendering layer. From beta test reports where some rather snakey code is executed equally fast on all phones, but not anything having to do with pixels…e.g. fetch, process and assemble data to push to 100 sub-groups of a big scrolling group… wink of an eye… actually build and layout the sub-groups in the UI and display: slow as molasses on android. BR _______________________________________________ use-livecode mailing list [hidden email] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode 
>
>  
 
 
 
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
Since we do not need to check whether a folder exists or not before creating it as LiveCode will not create duplicate folders, here is a script that will create nested folders:

on mouseUp
   put  specialFolderPath("desktop")& "/testFolder/testOne/test/result" into tFolder
   set the itemDel to "/"
   repeat with i = 1 to the number of items of tFolder
      put item 1 to i of tFolder into tFolderToCreate
      create folder tFolderToCreate
   end repeat
end mouseUp

Regards
Tore

> 7. aug. 2017 kl. 19:57 skrev Sannyasin Brahmanathaswami via use-livecode <[hidden email]>:
>
> 2) Does it make sense to ask for an enhancement request for the engine to recursively create folders for a path where itemdel "/" and items -1,-2,-3 (sub folders) do not exist?

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode

> Brian wrote:
> Check out _revSBEnsureFolder in revSBLibrary for example code that does this.

Brian, WOW! This is great insight!

on mouseUp
  put "/Users/admin/Documents/brian3/showed/us/the/trick/of/marcus/" into ff
  call "revSBEnsureFolder ff" of stack "revSBLibrary"
  launch document ff
end mouseUp

> Tore wrote:
> on mouseUp
>    put  specialFolderPath("desktop")& "/testFolder/testOne/test/result" into tFolder
>    set the itemDel to "/"
>    repeat with i = 1 to the number of items of tFolder
>       put item 1 to i of tFolder into tFolderToCreate
>       create folder tFolderToCreate
>    end repeat
> end mouseUp

Clever, Tore.


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
I just came to this myself before  coming back here

put item -1 of pURL into tFile
   put item 1 to -2 of pURL into tFolder
   put tDF &"/" & tFolder into tCompletePath
   
   # loop to create sub folders
   # Of course we know tDF exists,
   # but we don't know about any folder after that
   
   repeat for each item x in tFolder
      put "/" & x after tNextFolder
            put tDF & tNextFolder into tSubFolder
      if there is not a folder tSubFolder then
         create folder tSubFolder
         put the result
      end if
   end repeat  
   
   return tCompletePath &"/" & tFile

but your function is better

BR


 

On 8/7/17, 8:41 AM, "use-livecode on behalf of Tore Nilsen via use-livecode" <[hidden email] on behalf of [hidden email]> wrote:

    Since we do not need to check whether a folder exists or not before creating it as LiveCode will not create duplicate folders, here is a script that will create nested folders:
   
    on mouseUp
       put  specialFolderPath("desktop")& "/testFolder/testOne/test/result" into tFolder
       set the itemDel to "/"
       repeat with i = 1 to the number of items of tFolder
          put item 1 to i of tFolder into tFolderToCreate
          create folder tFolderToCreate
       end repeat
    end mouseUp
   
    Regards
    Tore

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
Wha??? I didn't know this existed. I have a need for that too! I use a repeat loop to do this. I suppose that is what this function does as well.

Bob S


> On Aug 7, 2017, at 12:12 , hh via use-livecode <[hidden email]> wrote:
>
>> Brian wrote:
>> Check out _revSBEnsureFolder in revSBLibrary for example code that does this.
>
> Brian, WOW! This is great insight!
>
> on mouseUp
>  put "/Users/admin/Documents/brian3/showed/us/the/trick/of/marcus/" into ff
>  call "revSBEnsureFolder ff" of stack "revSBLibrary"
>  launch document ff
> end mouseUp


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recursive folder creation

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
> Bob wrote:
> Wha??? I didn't know this existed. I have a need for that too! I use
> a repeat loop to do this. I suppose that is what this function does as well.

Here is it, for a "direct" call, in case revSBLibrary is not available.
It does the same as Tore's (and probably your) script but is recursive.

# Creates a folder and all parents as required. By Marcus van Houdt.
on revSBEnsureFolder pFolder
  set the itemDel to "/"
  if there is no folder pFolder and pFolder is not empty then
    revSBEnsureFolder item 1 to -2 of pFolder
    if the result is not empty then return the result
    create folder pFolder
    return the result
  end if
end revSBEnsureFolder


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...