Thread: Windows file paths.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User redruby147's Avatar
    Join Date
    Sep 2008
    Location
    England
    Posts
    37

    Windows file paths.

    I'm not sure how to deal with file paths when programming in windows. Here is my attempt thus far.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    char eclipse[150];
    
    int main()
    {   
        strcpy(eclipse, "C:\Documents and Settings\Owner\Desktop\eclipse\eclipse.exe -vm C:\WINDOWS\system32\javaw.exe");
        system(eclipse);
        return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    \\, not \.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    / also works in place of \\ if you want.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Elysia View Post
    / also works in place of \\ if you want.
    It does in things like fopen et al. that are handled by the C runtime. The dos box/shell/command prompt/whatever that system uses has no earthly idea what forward slashes are.

  5. #5
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    "Windows" hasn't cared which you use since Dos 2. command.com (the 16-bit command prompt) and the NT4 version of cmd treat / as a switch char rather than part of a path but since Win2k, it's not fussed which you use.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    "Windows" hasn't cared which you use since Dos 2. command.com (the 16-bit command prompt) and the NT4 version of cmd treat / as a switch char rather than part of a path but since Win2k, it's not fussed which you use.
    Although that's true when specifying relative paths, XP's command prompt has a problem when a drive letter is followed by anything but a backslash.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    How so?
    cd C:/
    Works fine.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Code:
    C:\>cd c:/work
    
    C:\Work>cd c:\work
    
    C:\Work>cd c:/work
    The system cannot find the path specified.
    Seems to be just a hole where in one particular circumstance, both options aren't supported.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    *shrug*
    c:\>md work
    c:\>cd c:/work
    c:\work>cd c:\work
    c:\work>cd c:/work
    c:\work>cd..
    c:\>rd work

    No problems. No errors.
    Perhaps it's related to XP and/or Vista only.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Elysia View Post
    *shrug*
    c:\>md work
    c:\>cd c:/work
    c:\work>cd c:\work
    c:\work>cd c:/work
    c:\work>cd..
    c:\>rd work

    No problems. No errors.
    Perhaps it's related to XP and/or Vista only.
    Wow, that works for me too (on Vista). I don't remember that ever working before.

    But in any case, it might only be a feature of a newer cmd.exe that changes / to \ for you. I'd only use '/' in C/C++ code and keep using \ outside of code.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by cpjust View Post
    Wow, that works for me too (on Vista). I don't remember that ever working before.

    But in any case, it might only be a feature of a newer cmd.exe that changes / to \ for you. I'd only use '/' in C/C++ code and keep using \ outside of code.
    I have a feeling (only a feeling) that this is not the shell, but cd. (Because cd does fancy parsing of the command line, etc., like being able to handle paths with spaces etc?) I can't get / to work as a path separator outside of cd (note that OP is not using cd), but then I'm not running Vista.,

  12. #12
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by tabstop View Post
    I have a feeling (only a feeling) that this is not the shell, but cd. (Because cd does fancy parsing of the command line, etc., like being able to handle paths with spaces etc?) I can't get / to work as a path separator outside of cd (note that OP is not using cd), but then I'm not running Vista.,
    You're right, I tried using the PRINT command with foward slashes and it complained about an invalid switch.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  13. #13
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    I cannot recall at the moment, but doesn't one also have to have an extra set of "" around the parts that contain spaces? eg
    Code:
     strcpy(eclipse, "\"C:\Documents and Settings\Owner\Desktop\eclipse\eclipse.exe\" -vm C:\WINDOWS\system32\javaw.exe");

  14. #14
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Kennedy View Post
    I cannot recall at the moment, but doesn't one also have to have an extra set of "" around the parts that contain spaces?
    Only if the pathname is being passed to the cmd.exe shell. If you are just opening a file or executing a program directly (i.e. not through system() ) then the spaces don't matter.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #15
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    To further clarify - I tested the above commands on several XP machines in various degrees of updated-ness (SP1, SP2, SP3) and got the same results each time. I haven't tried on Vista.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM