MakeSureDirectoryPathExists fail [SOLVED]

Just starting out? Need help? Post your questions and find answers here.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

MakeSureDirectoryPathExists fail [SOLVED]

Post 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
Last edited by eJan on Sat Nov 12, 2016 8:22 pm, edited 1 time in total.
Image
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: MakeSureDirectoryPathExists fail

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: MakeSureDirectoryPathExists fail

Post by ts-soft »

This old API is only ASCII and PB 5.50 is only Unicode!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: MakeSureDirectoryPathExists fail [SOLVED]

Post 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
Last edited by eJan on Sun Nov 13, 2016 8:27 pm, edited 1 time in total.
Image
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: MakeSureDirectoryPathExists fail [SOLVED]

Post by infratec »

Or:

Code: Select all

Debug MakeSureDirectoryPathExists_(Ascii("C:\test123\"))
Bernd
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: MakeSureDirectoryPathExists fail [SOLVED]

Post 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().
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: MakeSureDirectoryPathExists fail [SOLVED]

Post 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
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: MakeSureDirectoryPathExists fail [SOLVED]

Post 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\")
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: MakeSureDirectoryPathExists fail [SOLVED]

Post by eJan »

Thanks to all. Solved now. :D
Image
Post Reply