Page 1 of 1

Create Full Path Procedure

Posted: Tue Mar 10, 2026 2:51 am
by Randy Walker
You'll have to uncomment the CreateDirectory line for it to actually work, but run as is in Debugger to see how it would work in action. Of course, IF the drive exists it will fail to create the root directory. To be expected:

Code: Select all

Procedure Makepath(Sample$)
Sample$ = Trim(Sample$, "\")
Path$ = ""
For D = 1 To CountString(Sample$, "\") + 1
  Path$ + StringField(Sample$, D, "\") + "\"
  If FileSize(Path$) = -1
    Debug Path$
;   CreateDirectory(Path$)
  Else
    Debug Path$+" already exists"
  EndIf
Next D
EndProcedure

;Examples with and without trailing \
Makepath("D:\Eat\At\Joes\Bar\And\Grill\")
Delay(3000)
Makepath("D:\Eat\At\Joes\Bar\And\Grill")

Re: Create Full Path Procedure

Posted: Tue Mar 10, 2026 8:39 am
by BarryG
For Windows only, it's just one API command:

Code: Select all

SHCreateDirectory_(0,"D:\Eat\At\Joes\Bar\And\Grill\")

Re: Create Full Path Procedure

Posted: Tue Mar 10, 2026 8:59 am
by Randy Walker
BarryG wrote: Tue Mar 10, 2026 8:39 am For Windows only, it's just one API command:

Code: Select all

SHCreateDirectory_(0,"D:\Eat\At\Joes\Bar\And\Grill\")
Good to know. THANKS again BarryG !!!

Re: Create Full Path Procedure

Posted: Tue Mar 10, 2026 9:01 am
by BarryG
I've been using that forever. :)

Re: Create Full Path Procedure

Posted: Tue Mar 10, 2026 9:08 am
by Randy Walker
I'm, guessing change backslash to forward slash for Linux or MAC in my procedure to get it to work there. Cannot test here.

Re: Create Full Path Procedure

Posted: Tue Mar 10, 2026 9:42 am
by Piero
Randy Walker wrote: Tue Mar 10, 2026 9:08 am I'm, guessing change backslash to forward slash for Linux or MAC in my procedure to get it to work there. Cannot test here.

Code: Select all

Procedure Makepath(Sample$)
   Sample$ = Trim(Sample$, #PS$)
   If #PS$ = "/" : PS$ = #PS$ : EndIf
   For D = 1 To CountString(Sample$, #PS$) + 1
      Path2$ + StringField(Sample$, D, #PS$) + #PS$
      Path$ = PS$ + Path2$
      If FileSize(Path$) = -1
         Debug Path$
         ;   CreateDirectory(Path$)
      Else
         Debug Path$+" already exists"
      EndIf
   Next D
   Debug""
EndProcedure

;Examples with and without trailing #PS$
Makepath("D:\Eat\At\Joes\Bar\And\Grill\")
Makepath("D:\Eat\At\Joes\Bar\And\Grill")
Makepath("/Eat/At/Joes/Bar/And/Grill/")
Makepath("/Eat/At/Joes/Bar/And/Grill")

Re: Create Full Path Procedure

Posted: Tue Mar 10, 2026 2:30 pm
by Axolotl
BarryG wrote: Tue Mar 10, 2026 8:39 am For Windows only, it's just one API command:

Code: Select all

SHCreateDirectory_(0,"D:\Eat\At\Joes\Bar\And\Grill\")
Fun Fact: It's on the Deprecated APi Section since more than 10 years now. :oops: :mrgreen:
SHCreateDirectory is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions.

Re: Create Full Path Procedure

Posted: Tue Mar 10, 2026 5:47 pm
by HeX0R
better use

Code: Select all

If FileSize(Path$) <> -2
you might have files looking like directories

Re: Create Full Path Procedure

Posted: Tue Mar 10, 2026 6:39 pm
by Piero
HeX0R wrote: Tue Mar 10, 2026 5:47 pm better use

Code: Select all

If FileSize(Path$) <> -2
you might have files looking like directories
Not on Mac: you cannot create a dir if there's a file with the same name (at least not on Finder… don't wanna risk to try with PB and nuke my filesystem :mrgreen: )

Re: Create Full Path Procedure

Posted: Wed Mar 11, 2026 5:18 am
by Piero
:mrgreen:

Code: Select all

Procedure Makepath(Sample$)
   Protected PS$, Path$, Path2$, cs, D, fs
   Sample$ = Trim(Sample$, #PS$)
   If #PS$ = "/" : PS$ = #PS$ : EndIf
   cs = CountString(Sample$, #PS$) + 1
   For D = 1 To cs
      Path2$ + StringField(Sample$, D, #PS$) + #PS$
      Path$ = PS$ + Path2$
      fs = FileSize(Path$)
      If fs = -1
         ;  If Not CreateDirectory(Path$) : Debug Path$+" - Error!" : Break : EndIf
         Debug Path$
      ElseIf fs = -2
         Debug Path$+" - already exists"
      EndIf
   Next D
   Debug""
EndProcedure

Re: Create Full Path Procedure

Posted: Wed Mar 11, 2026 4:50 pm
by ebs
I use MakeSureDirectoryPathExists for the same purpose:

Code: Select all

MakeSureDirectoryPathExists_("D:\Eat\At\Joes\Bar\And\Grill\")
Axolotl wrote: Tue Mar 10, 2026 2:30 pm
BarryG wrote: Tue Mar 10, 2026 8:39 am For Windows only, it's just one API command:

Code: Select all

SHCreateDirectory_(0,"D:\Eat\At\Joes\Bar\And\Grill\")
Fun Fact: It's on the Deprecated APi Section since more than 10 years now. :oops: :mrgreen:
SHCreateDirectory is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions.