NO

Author Topic: mkdir() question.  (Read 5127 times)

dnaraG_1M

  • Guest
mkdir() question.
« on: February 29, 2012, 05:07:02 PM »
Hello all.
My 1st trip around the block with Pelles-C (old unix guy). All went well with my
app (win32 console) until I tried to create a directory tree. The mkdir function
is the problem. Compiled OK, but the Linker barfed saying "_mkdir not found".

Clearly, I'm missing a necessary module....But what?....
My includes are:
#include    <stdio.h>
#include    <stdlib.h>
#include    <io.h>
#include    <string.h>
#include    <ctype.h>
#include    <sys/types.h>
#include    <sys/stat.h>
#include    <dirent.h>
#include    <direct.h>
#include    <windows.h>

Thought that I needed <dir.h>, but the Compiler complains that it does not
exist. Doggone it, I just don't understand that win32 stuff yet.....

I would appreciate any comments or Links that might explain how to get
mkdir() working under Pelles......thanks in advance.

cheers,
johnd
 

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: mkdir() question.
« Reply #1 on: February 29, 2012, 05:40:49 PM »
Use compiler option -Go  (Define compatibility names) for oldnames.lib
May the source be with you

dnaraG_1M

  • Guest
Re: mkdir() question.
« Reply #2 on: February 29, 2012, 06:06:01 PM »
>Use compiler option -Go  (Define compatibility names) for oldnames.lib

HA!
Took your advice and there is Joy in Mudville today!!
[Would have never guessed I needed to search for info on "oldnames".....]
[mkdir - an old name..??...       Well ok, it is what it is......]

I thank you muchly.


Till my next brain-hiccup,
cheers
johnd

czerny

  • Guest
Re: mkdir() question.
« Reply #3 on: February 29, 2012, 06:12:06 PM »
Hi JohnD,

you may also consider the api functions: CreateDirectory, CreateDirectoryEx or CreateDirectoryTransacted.

czerny

CommonTater

  • Guest
Re: mkdir() question.
« Reply #4 on: February 29, 2012, 06:42:55 PM »
Hello all.
My 1st trip around the block with Pelles-C (old unix guy). All went well with my
app (win32 console) until I tried to create a directory tree. The mkdir function
is the problem. Compiled OK, but the Linker barfed saying "_mkdir not found".

Clearly, I'm missing a necessary module....But what?....
My includes are:
#include    <stdio.h>
#include    <stdlib.h>
#include    <io.h>
#include    <string.h>
#include    <ctype.h>
#include    <sys/types.h>
#include    <sys/stat.h>
#include    <dirent.h>
#include    <direct.h>
#include    <windows.h>

Thought that I needed <dir.h>, but the Compiler complains that it does not
exist. Doggone it, I just don't understand that win32 stuff yet.....

I would appreciate any comments or Links that might explain how to get
mkdir() working under Pelles......thanks in advance.

cheers,
johnd

Hi John, welcome to the forums!
 

First off, a little windows thing, for you...  Press F1 on your keyboard.  That's the standard windows help key.  In Pelles C, F1 will bring up full documentation on the toolchain, IDE and librairies.  If you place your text cursor on a coloured keyword, pressing F1 brings up detail on that keyword for you.  Help files are our friends!

Also note that in the help file non-standard functions are clearly identified.  In the library they are also prefixed with an underscore.  Hense timo's suggestion for the -Go compiler option, which is enabled in project settings by the Define Compatibility Names option.

Since every OS has it's own idea about the right and wrong ways, C-99 does not include any standard way of searching or manipulating directories.  So you have two choices, you can either use the direct.h header  and _mkdir()  or go to the Windows API and use CreateDirectory() 
 
The catch is that you can only create one directory at a time ...  _mkdir("fred\barney"); ...  isn't going to work and since windows uses backslashes you have to "escape" them like this... _mkdir("fred\\barney"); ... to get the single backslash for your pathname.
 
For example:
Code: [Select]
#include <stdio.h>
#include <direct.h>
 
int main (void)
  {
 
    if (_mkdir("fred\\ethel") )
      puts("Can't do multiples\n\n");
 
 
    if (! _mkdir("fred"))
      if (! _mkdir("fred\\ethel"))
        puts("Ok that worked");
 
    return 0; }

And, just as a suggestion... it's probably not a good idea to include any headers you don't actually need on a given source page. You run the risk of name collisions and it slows the compiler down a fair bit.
 


 
« Last Edit: February 29, 2012, 06:51:20 PM by CommonTater »

dnaraG_1M

  • Guest
Re: mkdir() question.
« Reply #5 on: February 29, 2012, 07:56:50 PM »
First off, a little windows thing, for you...  Press F1 on your keyboard.  That's the standard windows help key.  In Pelles C, F1 will bring up full documentation on the toolchain, IDE and librairies.  If you place your text cursor on a coloured keyword, pressing F1 brings up detail on that keyword for you.  Help files are our friends!
Amen.
As are Wiki, google, etc. Tried those first, of course.
And as is my luck, "mkdir" is not a "colored" word.
[sigh].

Also note that in the help file non-standard functions are clearly identified.  In the library they are also prefixed with an underscore.  Hense timo's suggestion for the -Go compiler option, which is enabled in project settings by the Define Compatibility Names option.
Oh!
And I stumbled around, finding the CCFLAGS in the Macro Tab and added it there.
.....The luck of fools.........

Since every OS has it's own idea about the right and wrong ways, C-99 does not
include any standard way of searching or manipulating directories.  So you have two
choices, you can either use the direct.h header  and _mkdir()  or go to the Windows
API and use CreateDirectory()

More to learn....Is that true for console app, windows app. both???


The catch is that you can only create one directory at a time ...  _mkdir("fred\barney"); ...  isn't going to work and since windows uses backslashes
you have to "escape" them like this... _mkdir("fred\\barney"); ... to get the single
backslash for your pathname.

Funny thing about them slashes and backslashes.................

From unix/linux, I'm kinda of used to escaping darn near EVERYTHING!
Shouldn't be a huge problem....gotta enough of those just learning
something new......

Thanks for all the help.

cheers,
johnd

CommonTater

  • Guest
Re: mkdir() question.
« Reply #6 on: February 29, 2012, 10:52:33 PM »
First off, a little windows thing, for you...  Press F1 on your keyboard.  That's the standard windows help key.  In Pelles C, F1 will bring up full documentation on the toolchain, IDE and librairies.  If you place your text cursor on a coloured keyword, pressing F1 brings up detail on that keyword for you.  Help files are our friends!
Amen.
As are Wiki, google, etc. Tried those first, of course.
And as is my luck, "mkdir" is not a "colored" word.
[sigh].

Without the -Go option _mkdir highlights... with it mkdir highlights by itself.

Quote
Also note that in the help file non-standard functions are clearly identified.  In the library they are also prefixed with an underscore.  Hense timo's suggestion for the -Go compiler option, which is enabled in project settings by the Define Compatibility Names option.
Oh!
And I stumbled around, finding the CCFLAGS in the Macro Tab and added it there.
.....The luck of fools.........
On the top menu click -> Project -> Project Options -> Compiler -> Enable compatibility names.

Spend some time exploring the UI... it's VERY complete.


Quote
Since every OS has it's own idea about the right and wrong ways, C-99 does not
include any standard way of searching or manipulating directories.  So you have two
choices, you can either use the direct.h header  and _mkdir()  or go to the Windows
API and use CreateDirectory()

More to learn....Is that true for console app, windows app. both???
True for all.  It's all using the same file system. 

Nothing stops you from using Windows API calls in console programs... you can even set up a message dispatcher.

Quote
Thanks for all the help.

Any time....