Author Topic: Manifold MKDIR  (Read 561 times)

Robert

  • Hero Member
  • *****
  • Posts: 601
    • View Profile
Manifold MKDIR
« on: August 04, 2020, 01:54:19 AM »
BCX MKDIR will create only one new folder per call, so only the last component of the MKDIR argument is used to create a new folder.

Here is a snippet that uses the Windows system MKDIR command to create several folders at once.

In the example, you may be tempted to move the DQ$ encapsulation to the PathStr$, but I'm sure I heard someone say, "No no !!!"

Code: [Select]

DIM PathStr$
 
PathStr$ = "C:\Windows\Temp\BCX\Does\It All"

SHELL "MKDIR " & DQ$ & PathStr$ & DQ$

IF EXIST(PathStr$) = 1 THEN
  PRINT "MKDIR has created " & PathStr$
ELSE
  PRINT "MKDIR did not create " & PathStr$
END IF


It would be interesting to see a pure BCX code that does this.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
Re: Manifold MKDIR
« Reply #1 on: August 04, 2020, 10:02:53 AM »
Robert -- This seems to do the trick ... not extensively tested.

It basically tries to create the component sub-folders one-at-time. 
If any of the preceding sub-folders already exist, it simply continues on to the next sub-folder (to the right).


Code: [Select]
DIM PathStr$
PathStr$ = "c:\Temp\BCX\Does\It All"

MKDIREX(PathStr$)  : PRINT

IF EXIST(PathStr$) = 1 THEN
  PRINT "MKDIR has created " & PathStr$
ELSE
  PRINT "MKDIR did not create " & PathStr$
END IF

SUB MKDIREX (A$)
  LOCAL Buf$[100]
  LOCAL Tmp$
  LOCAL Elements

  Elements = SPLIT (Buf$, A$, "\") - 1

  FOR INT i = 0 TO Elements
    Tmp$ = Tmp$ + Buf$[i] + "\"
    MKDIR Tmp$
  NEXT
END SUB

« Last Edit: August 04, 2020, 10:07:58 AM by MrBcx »

Robert

  • Hero Member
  • *****
  • Posts: 601
    • View Profile
Re: Manifold MKDIR
« Reply #2 on: August 04, 2020, 12:06:59 PM »
Robert -- This seems to do the trick ... not extensively tested.

It basically tries to create the component sub-folders one-at-time. 
If any of the preceding sub-folders already exist, it simply continues on to the next sub-folder (to the right).


Code: [Select]
DIM PathStr$
PathStr$ = "c:\Temp\BCX\Does\It All"

MKDIREX(PathStr$)  : PRINT

IF EXIST(PathStr$) = 1 THEN
  PRINT "MKDIR has created " & PathStr$
ELSE
  PRINT "MKDIR did not create " & PathStr$
END IF

SUB MKDIREX (A$)
  LOCAL Buf$[100]
  LOCAL Tmp$
  LOCAL Elements

  Elements = SPLIT (Buf$, A$, "\") - 1

  FOR INT i = 0 TO Elements
    Tmp$ = Tmp$ + Buf$[i] + "\"
    MKDIR Tmp$
  NEXT
END SUB


Hi MrBCX:

This also works

Code: [Select]

PathStr$ = "\Temp\BCX\Does\It All"


Thank you for this, I will add it to the Help file.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
Re: Manifold MKDIR
« Reply #3 on: August 04, 2020, 01:31:23 PM »

Hi MrBCX:

This also works

Code: [Select]

PathStr$ = "\Temp\BCX\Does\It All"


Yep ... I tried that too during testing.  In that example, it builds off the cwd which is what I wanted.

Quote
Thank you for this, I will add it to the Help file.

Should I build it into BCX?   

Perhaps a command called MKPATH$ (szPath$)  ??



Robert

  • Hero Member
  • *****
  • Posts: 601
    • View Profile
Re: Manifold MKDIR
« Reply #4 on: August 04, 2020, 02:54:29 PM »

Hi MrBCX:

This also works

Code: [Select]

PathStr$ = "\Temp\BCX\Does\It All"


Yep ... I tried that too during testing.  In that example, it builds off the cwd which is what I wanted.

Quote
Thank you for this, I will add it to the Help file.

Should I build it into BCX?   

Perhaps a command called MKPATH$ (szPath$)  ??


+1