working with directories

This is a discussion on working with directories within the C Programming forums, part of the General Programming Boards category; I need to create, remove and check if a directory exists. It seems that theres no standard/portable way to do ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    5

    working with directories

    I need to create, remove and check if a directory exists. It seems that theres no standard/portable way to do this? Is this correct? Are there "recommended" functions, or should I just use system()? To check if a directory exists should I just change working path and use the return value? It's for a windows console app. Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    > It seems that theres no standard/portable way to do this? Is this correct?
    Correct - there is no standard way

    Here's a recent thread which may help
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    5
    Thanks - bizarre
    how are you supposed to write portable code
    guess I'll start including windows.h
    is it reasonable to check if the directory exists using:

    #include windows.h
    if (SetCurrentDirectory("z:\mydir\") == 0)

    I can't check, because I'm at work and I'm not allowed to install a compiler grrrrrrrrrrrrr....

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    > how are you supposed to write portable code
    Read this

    > if (SetCurrentDirectory("z:\mydir\") == 0)
    I think this has something to do with FTP

    This is from MSDN
    Directory Control
    These routines access, modify, and obtain information about the directory structure.

    Directory-Control Routines

    Routine Use
    _chdir, _wchdir Change current working directory
    _chdrive Change current drive
    _getcwd, _wgetcwd Get current working directory for default drive
    _getdcwd, _wgetdcwd Get current working directory for specified drive
    _getdrive Get current (default) drive
    _mkdir, _wmkdir Make new directory
    _rmdir, _wrmdir Remove directory
    _searchenv, _wsearchenv Search for given file on specified paths
    To test for a directory
    _stat, _wstat, _stati64, _wstati64
    Get status information on a file.

    int _stat( const char *path, struct _stat *buffer );

    .....

    buffer contains a member called st_mode

    Bit mask for file-mode information. The _S_IFDIR bit is set if path specifies a directory; the _S_IFREG bit is set if path specifies an ordinary file or a device. User read/write bits are set according to the file’s permission mode; user execute bits are set according to the filename extension.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 06-30-2005, 09:03 AM
  2. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 08:47 PM
  3. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  4. ANSI - working with directories
    By sean345 in forum C Programming
    Replies: 1
    Last Post: 06-01-2002, 05:43 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 05:08 AM

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