CreateDirectoryEx (crossplattform)

Share your advanced PureBasic knowledge/code with the community.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

CreateDirectoryEx (crossplattform)

Post by ts-soft »

a very simple way to create all dirs at once
(MacOS not tested)

Code: Select all

EnableExplicit

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
CompilerElse
  ImportC ""
    system(cmd.p-utf8)
  EndImport
CompilerEndIf

Procedure CreateDirectoryEx(DirPath.s)
  CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    RunProgram(GetEnvironmentVariable("COMSPEC"), "/c mkdir " + #DQUOTE$ + DirPath + #DQUOTE$, "", #PB_Program_Wait | #PB_Program_Hide)
    If FileSize(DirPath) = -2
      ProcedureReturn #True
    EndIf
  CompilerDefault
  If Not system("mkdir -p " + #DQUOTE$ + DirPath + #DQUOTE$)
    ProcedureReturn #True
  EndIf
  CompilerEndSelect
EndProcedure

Define.s Path = GetHomeDirectory() + "test1/test2/tesatäöü"


Debug CreateDirectoryEx(Path)
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
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: CreateDirectoryEx (crossplattform)

Post by rsts »

Very useful.

Thanks for sharing :)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: CreateDirectoryEx (crossplattform)

Post by Kwai chang caine »

Thanks Ts-Soft 8)
Just a question, what is the difference with MakeSureDirectoryPathExists_() ?
ImageThe happiness is a road...
Not a destination
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: CreateDirectoryEx (crossplattform)

Post by ts-soft »

Kwaï chang caïne wrote:Thanks Ts-Soft 8)
Just a question, what is the difference with MakeSureDirectoryPathExists_() ?
MakeSureDirectoryPathExists_ is not Unicode compatible and not available on all Win Versions.
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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: CreateDirectoryEx (crossplattform)

Post by Kwai chang caine »

and not available on all Win Versions.
Waoouuuh!!! fortunately i ask you this question.... :shock:
Because i use it frequently, and don't know it's possible a day that don't work everywhere

Again thanks TsSoft, for the sharing and your answer 8)
ImageThe happiness is a road...
Not a destination
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: CreateDirectoryEx (crossplattform)

Post by ts-soft »

It is only missing on some UserDefined Win9x installation, not a problem in 2014 :wink:
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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: CreateDirectoryEx (crossplattform)

Post by Kwai chang caine »

Always good to know this missing, even if win 9x are far now...because again numerous PC works with 8)
The problem with the API, it's sometime she change and bill gates never ask at KCC if he have the right :mrgreen: :lol:
And it's like when, i have learning, thanks to the PB members, PathAddBackslash_(@Var) can be dangerous :shock:
The API are powerfull, but it's important to know her, before use it :oops:
Thanks for your tips 8)
ImageThe happiness is a road...
Not a destination
Post Reply