Page 1 of 1

MakeSureDirectoryPathExists fail [SOLVED]

Posted: Sat Nov 12, 2016 4:38 pm
by eJan
Hi to all.
I have installed PB v5.50 x64 & x86, both exits with 1 when used

Code: Select all

MakeSureDirectoryPathExists_("C:\New Folder\")
, but the folder wasn't created, where PB v5.43 x64 LTS create folders with cuccess.
My OS Win 10 Pro x64 1607 14393.447

Re: MakeSureDirectoryPathExists fail

Posted: Sat Nov 12, 2016 5:51 pm
by Mistrel
This function requires a C string and does not have a Unicode variant.
This function does not support Unicode strings. To specify a Unicode path, use the SHCreateDirectoryEx function.
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Re: MakeSureDirectoryPathExists fail

Posted: Sat Nov 12, 2016 5:51 pm
by ts-soft
This old API is only ASCII and PB 5.50 is only Unicode!

Re: MakeSureDirectoryPathExists fail [SOLVED]

Posted: Sat Nov 12, 2016 8:27 pm
by eJan
Thanks, now i'm using Shardik's solution

Code: Select all

Debug SHCreateDirectory_(0, "C:\Temp\Kcc")
http://www.purebasic.fr/english/viewtop ... 11#p495011

Re: MakeSureDirectoryPathExists fail [SOLVED]

Posted: Sat Nov 12, 2016 10:45 pm
by infratec
Or:

Code: Select all

Debug MakeSureDirectoryPathExists_(Ascii("C:\test123\"))
Bernd

Re: MakeSureDirectoryPathExists fail [SOLVED]

Posted: Sat Nov 12, 2016 11:27 pm
by Mistrel
infratec wrote:

Code: Select all

Debug MakeSureDirectoryPathExists_(Ascii("C:\test123\"))
That is a memory leak. You have to manually free the buffer, as per the documentation:
Creates an Ascii representation of the string. When no more needed, the buffer needs to be freed with FreeMemory().

Re: MakeSureDirectoryPathExists fail [SOLVED]

Posted: Sun Nov 13, 2016 11:28 am
by infratec
This was only to show what is meant with: ASCII is required.
And it's no memoryleak in production, because Debug is in front :wink:

But, only for completeness, here is the correct solution:

Code: Select all

Define *Ascii

*Ascii = Ascii("C:\test123\")
If *Ascii
  MakeSureDirectoryPathExists_(*Ascii)
  FreeMemory(*Ascii)
EndIf
or as Procedure

Code: Select all

Procedure.i MakeSureDirectoryPathExists(Path$)
  
  Protected Result.i, *Ascii
  
  *Ascii = Ascii("C:\test123\")
  If *Ascii
    Result = MakeSureDirectoryPathExists_(*Ascii)
    FreeMemory(*Ascii)
  EndIf
  
  ProcedureReturn Result
  
EndProcedure
Bernd

Re: MakeSureDirectoryPathExists fail [SOLVED]

Posted: Sun Nov 13, 2016 11:48 am
by Bisonte
or with Prototype

Code: Select all

Prototype proto_msdpe(Path.p-Ascii)

Procedure _MSDPE(Path.s)
  ProcedureReturn MakeSureDirectoryPathExists_(Path)  
EndProcedure

Global MakeSureDirectoryPathExists.proto_msdpe = @_MSDPE()

Debug MakeSureDirectoryPathExists("E:\d\c\b\a\")

Re: MakeSureDirectoryPathExists fail [SOLVED]

Posted: Sun Nov 13, 2016 8:30 pm
by eJan
Thanks to all. Solved now. :D