MKDIR Question

New to FreeBASIC? Post your questions here.
nimdays
Posts: 234
Joined: May 29, 2014 22:01
Location: ID

MKDIR Question

Postby nimdays » Aug 01, 2020 5:07

This doesn't create any folder

Code: Select all

?mkdir ("foo\bar\baz")


I think the documentation should be updated because you must create it manually

Code: Select all

?mkdir ("foo")
?mkdir ("foo\bar")
?mkdir ("foo\bar\baz")
fxm
Posts: 9713
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: MKDIR Question

Postby fxm » Aug 01, 2020 5:57

Yes, the description in the documentation can be ambiguous, because if the parameter passed is not a simple folder/directory name, but a path to a sub-folder/sub-directory, it is not specified that the parent folder(s)/directory(s) specified in the path must already exist.

Documentation updated:
KeyPgMkdir → fxm [clarified the documentation in case of the passed parameter is a path to a sub-folder/sub-directory]
jj2007
Posts: 1523
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: MKDIR Question

Postby jj2007 » Aug 01, 2020 8:07

Wouldn't it be nicer to update FB instead of the documentation? For example, MakeDir allows this (and it was no rocket science writing it):

Code: Select all

  MakeDir "tmp\new\folder"
  .if Zero?
   PrintLine "created"
  .else
   PrintLine "not created: ", Err$()
  .endif
nimdays
Posts: 234
Joined: May 29, 2014 22:01
Location: ID

Re: MKDIR Question

Postby nimdays » Aug 01, 2020 8:26

Thanks All
fxm
Posts: 9713
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: MKDIR Question

Postby fxm » Aug 01, 2020 8:39

Currently, the MkDir FreeBASIC works like the MkDir QB.
Therefore it's not a FB bug, and so I only clarified the documentation.

As for improving the MkDir issued from QB (or creating a new more efficient keyword), that's another point.
xlucas
Posts: 277
Joined: May 09, 2014 21:19
Location: Argentina

Re: MKDIR Question

Postby xlucas » Aug 08, 2020 23:47

MkDir is based in QB, but also, QB's MkDir is based on DOS's md/mkdir command, which, if I remember well, did not allow for creating chains of directories in one pass either. I am using GNU/Linux and I have just tried mkdir in the console and it also disallows doing this. I'd say this is standard mkdir behaviour.

Somebody new with FreeBasic or with programming in general can, of course, be excused for assuming mkdir is more powerful and indeed, I agree it would be easy and interesting to give it more power, but this could also be a risk. A misbehaved program could easily mess up if it created chains of directories by mistake. And besides, if MkDir is updated, directory deletion should work the same way for consistency, but that'd be even more dangerous. It's really something to discuss!
marcov
Posts: 2971
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: MKDIR Question

Postby marcov » Aug 09, 2020 11:55

I do think that having a function for multi level dir creation is useful. The Delphi name for the function is "ForceDirectories".

Recursive directory deletion doesn't have to be dangerous, if like rmdir it only removes empty dirs, and returns an error on non empty.

So rmdir, not rm -rf :-)

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 5 guests