Obtain Cd-Rom path and one more

This is a discussion on Obtain Cd-Rom path and one more within the Windows Programming forums, part of the Platform Specific Boards category; 1) Can anyone tell how can i obtain the primary cd/dvd - rom path using C 2) Check my code. ...

  1. #1
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142

    Obtain Cd-Rom path and one more

    1) Can anyone tell how can i obtain the primary cd/dvd - rom path using C

    2)
    Check my code. I want to copy "setup.exe" using C programming. iF THE path does not contain spaces the copy of the file completes perfect but if i want to use spaces between the path nothing happens.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <Windows.h>
    #include <string.h>
    
    int main(void)
    {
    	char cp[80] = "copy setup.exe " ,*destination;
    		
            /*Allocate memory for strings*/     
            destination = malloc (40 * sizeof(char));
        
            destination = "C:\\Program Files\\top";
                     
    	    strcat(cp,destination);
    	    printf("%s\n",cp);
    	    system(cp);		
      
     return 0;
    }
    What can i do ?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Use the win32 API to copy the files, rather than using system().

    If you 'must' use system(), then you need to use the same quoting rules that you would use on the command line.

    Say
    destination = "\"C:\\Program Files\\top\"";
    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
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I have no idea how you find the CD-ROM - there's probably some way to find out what type of drive(s) there are in the system - and you should consider that there may be more than one CD-ROM drive in the system [my home computer has one one CD burner and one DVD-rom - both of which the computer considers CD-ROM type drives].

    As to "spaces in the path", you should use quotes, e.g. your string should be
    Code:
    copy setup.exe "c:\program files\..."
    Use \" to insert quotes into a string.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,672
    Use GetLogicalDrives() to determine what drive letters exist.
    Use GetDriveType() to determine if it's a CDROM.

    gg

  5. #5
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142
    Thanks !!!!

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