CreateDirectory dont work

Just starting out? Need help? Post your questions and find answers here.
Grimmjow
New User
New User
Posts: 8
Joined: Mon Jan 04, 2010 1:28 am

CreateDirectory dont work

Post by Grimmjow »

Code: Select all

Result = CreateDirectory("C:\Data\Audio\SOUNDS\AMBIENCES\")

If Result = #False
  Debug "Error"
Else
  Debug "Done"
EndIf
Hey guys, i have a problem with CreateDirectory command.
It just does not create following folder path.
I tryed everything but it doesnt work. Any ideas ?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: CreateDirectory dont work

Post by Kaeru Gaman »

CreateDirectory does not create PATHs, or it would be named CreatePath.

you'll need to create a path recursively level by level.

Code: Select all

SetCurrentDirectory(GetPathPart(ProgramFilename()))
res = CreateDirectory( "test" )
Debug res

SetCurrentDirectory("test")
res = CreateDirectory( "testA" )
Debug res

SetCurrentDirectory("testA")
res = CreateDirectory( "testB" )
Debug res
also, make sure your process has write access granted.
better do not create a directory whereelse than in the APPDATA folder of the User Profile.
only an Installer should do that, and it needs Admin rights to do so.
oh... and have a nice day.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: CreateDirectory dont work

Post by ts-soft »

Kaeru Gaman wrote: better do not create a directory whereelse than in the APPDATA folder of the User Profile.
only an Installer should do that, and it needs Admin rights to do so.
:shock:
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: CreateDirectory dont work

Post by Kaeru Gaman »

:?: ... wasn't I precise or verbose enough for your taste ... Image
oh... and have a nice day.
Grimmjow
New User
New User
Posts: 8
Joined: Mon Jan 04, 2010 1:28 am

Re: CreateDirectory dont work

Post by Grimmjow »

Ah i see now. But still i have no idea how to implement it.
In my code i have a structure that has Path option.
There i store my folder paths and later i create this stored folders with help
of ForEach Loop:

Code: Select all

ForEach Folder()
  If Not FolderExists(ProgramRoot + Folder()\Path)
    Result = CreateDirectory(ProgramRoot + Folder()\Path)
    If Result = #False
      Debug Folder()\Path
      End
    EndIf
  EndIf
Next
Mostly my Folder()\Path looks like : "C:\Program Files\My Program\Bin\Data\Systems\
So this code should create "Bin\Data\Systems\ but well.
So any idea how i can implement following code you gave me with this one ?

Thanks !
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: CreateDirectory dont work

Post by Kaeru Gaman »

hm....
I would suggest you write your own CreatePath Procedure you put in the place where your CreateDirectory(ProgramRoot + Folder()\Path) is now.
better pass ProgramRoot and Folder()\Path as two parameters.
within that procedure you first cut the path into pieces using StringField.
then you can start with ProgramRoot, and add piece by piece.
first check if it already exists, if not, create it, and proceed to the next level.

there also was a WinAPI function to make sure a path exists, but I can't recall it's name...
oh... and have a nice day.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: CreateDirectory dont work

Post by ts-soft »

Kaeru Gaman wrote::?: ... wasn't I precise or verbose enough for your taste ... Image
Was absolute false. APPDATA is to write or create Directories for your apllication!
That is the path for
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: CreateDirectory dont work

Post by Kaeru Gaman »

well, wasn't the question related to his application?
where else should a command he compiles should be?

and when he creates a folder tree beyond his "ProgramRoot",it seems to be an installer he is writing, doesn't it?

and without question this is a task that will hit access rights issues, isn't it?


... now, please state again what exactly was wrong with my hint?
oh... and have a nice day.
Grimmjow
New User
New User
Posts: 8
Joined: Mon Jan 04, 2010 1:28 am

Re: CreateDirectory dont work

Post by Grimmjow »

Well its not an installer :) Its an updater for a game :)

Code: Select all

Procedure CreatePath(Root.s, Path.s)
  Protected LastFolder.s = Root
   
  For i = 1 To CountString(Path, "\")
    FolderName.s = StringField(Path, i, "\")
    SetCurrentDirectory(LastFolder)
    If Not FolderExists(FolderName)
      CreateDirectory(FolderName)
    EndIf
    LastFolder = FolderName
  Next
EndProcedure
Ok i tested it and came to this code.. Now tell me if its ok to use or not :)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: CreateDirectory dont work

Post by Kaeru Gaman »

an Updater is on the same Level as an Installer.

it should ask for Admin righst if the user isn't admin,
I don't know if you need to invoke this or if the OS handles it automatically if it tries to create a directory.
oh... and have a nice day.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: CreateDirectory dont work

Post by Kuron »

Kaeru Gaman wrote:I don't know if you need to invoke this
The trustinfo of the manifest should be what requests administrator privileges via "requireAdministrator".
Last edited by Kuron on Sun Feb 21, 2010 11:37 pm, edited 1 time in total.
Best wishes to the PB community. Thank you for the memories. ♥️
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: CreateDirectory dont work

Post by eJan »

This API should work:

Code: Select all

MakeSureDirectoryPathExists_("C:\Data\Audio\SOUNDS\AMBIENCES\")
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: CreateDirectory dont work

Post by Trond »

ts-soft wrote:
Kaeru Gaman wrote::?: ... wasn't I precise or verbose enough for your taste ... Image
Was absolute false. APPDATA is to write or create Directories for your apllication!
That is the path for
He meant that you shouldn't create directories anywhere else.
wallgod
User
User
Posts: 48
Joined: Wed Oct 06, 2010 2:03 pm

Re: CreateDirectory dont work

Post by wallgod »

eJan wrote:This API should work:

Code: Select all

MakeSureDirectoryPathExists_("C:\Data\Audio\SOUNDS\AMBIENCES\")
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Good call, eJan!
Procrastinators unite... tomorrow!
Post Reply