Need Help

This is a discussion on Need Help within the C Programming forums, part of the General Programming Boards category; Hi Dont post often but could someone help here as Im trying to create a folder using c in win ...

  1. #1
    Patent Pending GSLR's Avatar
    Join Date
    Sep 2001
    Posts
    134

    Unhappy Need Help

    Hi

    Dont post often but could someone help here as Im trying to create a folder using c in win 98 Os ,Ican create files but the folder thing has got me.
    Also here is a snippet

    int main()
    {
    FILE *ptr;
    char filename[]="test.txt":
    ptr = fopen(filename,"w");
    fclose(ptr);
    return 0;
    }

    Ok this creates a file in the directory that you are currently using , how do I get it to create the file elsewhere whilst still using the array.
    Tried this but i guess you all know the outcome

    ptr = fopen("c:/filename","w");
    or
    ptr = fopen("C:/"filename,"w"); ***Doesnt work****

    Ok Thanx
    Q

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    This is what MSDN Library says about the "_mkdir" function which is what you may need:
    _mkdir, _wmkdir
    Create a new directory.

    int _mkdir( const char *dirname );

    int _wmkdir( const wchar_t *dirname );

    Routine Required Header Compatibility
    _mkdir <direct.h> Win 95, Win NT
    _wmkdir <direct.h> or <wchar.h> Win NT


    For additional compatibility information, see Compatibility in the Introduction.

    Libraries

    LIBC.LIB Single thread static library, retail version
    LIBCMT.LIB Multithread static library, retail version
    MSVCRT.LIB Import library for MSVCRT.DLL, retail version


    Return Value

    Each of these functions returns the value 0 if the new directory was created. On an error the function returns 1 and sets errno as follows:

    EEXIST

    Directory was not created because dirname is the name of an existing file, directory, or device

    ENOENT

    Path was not found

    Parameter

    dirname

    Path for new directory

    Remarks

    The _mkdir function creates a new directory with the specified dirname. _mkdir can create only one new directory per call, so only the last component of dirname can name a new directory. _mkdir does not translate path delimiters. In Windows NT, both the backslash ( \) and the forward slash (/ ) are valid path delimiters in character strings in run-time routines.

    _wmkdir is a wide-character version of _mkdir; the dirname argument to _wmkdir is a wide-character string. _wmkdir and _mkdir behave identically otherwise.

    Generic-Text Routine Mappings

    TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
    _tmkdir _mkdir _mkdir _wmkdir


    Example

    /* MAKEDIR.C */

    #include <direct.h>
    #include <stdlib.h>
    #include <stdio.h>

    void main( void )
    {
    if( _mkdir( "\\testtmp" ) == 0 )
    {
    printf( "Directory '\\testtmp' was successfully created\n" );
    system( "dir \\testtmp" );
    if( _rmdir( "\\testtmp" ) == 0 )
    printf( "Directory '\\testtmp' was successfully removed\n" );
    else
    printf( "Problem removing directory '\\testtmp'\n" );
    }
    else
    printf( "Problem creating directory '\\testtmp'\n" );
    }


    Output

    Directory '\testtmp' was successfully created
    Volume in drive C is CDRIVE
    Volume Serial Number is 0E17-1702

    Directory of C:\testtmp

    05/03/94 12:30p <DIR> .
    05/03/94 12:30p <DIR> ..
    2 File(s) 0 bytes
    17,358,848 bytes free
    Directory '\testtmp' was successfully removed


    Directory Control Routines

    See Also _chdir, _rmdir
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21