MKDIR Question

New to FreeBASIC? Post your questions here.
Post Reply
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

MKDIR Question

Post by nimdays »

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
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: MKDIR Question

Post by fxm »

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: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: MKDIR Question

Post by jj2007 »

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: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: MKDIR Question

Post by nimdays »

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

Re: MKDIR Question

Post by fxm »

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: 334
Joined: May 09, 2014 21:19
Location: Argentina

Re: MKDIR Question

Post by xlucas »

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: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: MKDIR Question

Post by marcov »

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 :-)
Post Reply