Page 1 of 1

CreateDirectory dont work

Posted: Sun Feb 21, 2010 3:31 pm
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 ?

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 3:48 pm
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.

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 3:51 pm
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:

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 3:53 pm
by Kaeru Gaman
:?: ... wasn't I precise or verbose enough for your taste ... Image

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 4:02 pm
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 !

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 4:09 pm
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...

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 4:14 pm
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

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 4:21 pm
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?

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 4:23 pm
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 :)

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 4:33 pm
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.

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 5:06 pm
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".

Re: CreateDirectory dont work

Posted: Sun Feb 21, 2010 7:57 pm
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

Re: CreateDirectory dont work

Posted: Thu Feb 25, 2010 12:50 pm
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.

Re: CreateDirectory dont work

Posted: Thu Oct 14, 2010 3:12 am
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!