directory path coding

This is a discussion on directory path coding within the C++ Programming forums, part of the General Programming Boards category; hi all, i need to set a directory path into a Cstring variable, as follows: CString directory; directory ="\D:\data\data"; but ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    74

    directory path coding

    hi all,

    i need to set a directory path into a Cstring variable, as follows:
    CString directory;
    directory ="\\D:\data\data";

    but error code occur said that d: is unrecognised character escape sequence, how do i cope with that?

    thanks!

  2. #2
    NotSoAvgProgrammer
    Join Date
    Jul 2007
    Location
    Virginia, U.S.
    Posts
    57
    Can you post the actual error message, it will help us help you easier.

    Joe
    A quality job is not necessarily a *good* job. A quality job is, by definition, conformance to requirements. Therefore a *good* job, may not be a quality job.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    74
    warning C4129: 'd' : unrecognized character escape

    since i need to use the creatfile function to read file in that directory, so i need to set path of that directory.
    Last edited by mr_empty; 11-18-2007 at 08:02 PM.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    directory ="\\D:\\data\\data";

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    74
    Code:
    i use these coding:
    
       dest=  "\\D:\\data\\data\\file14.txt";
       HANDLE hFile = CreateFile (dest, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0,NULL);
    
       if (hFile == INVALID_HANDLE_VALUE){// if setting/file not valid
    		DWORD dw = GetLastError ();
    		debug = "Step 1";
    		detail.DetailValue = debug;
    	}
    
    detail.DoModal();
    
    the above command display "step 1"
    
    i still can't access the file, do u know why? thanks very much!!

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    74
    now i use this:

    Code:
    HANDLE hFile = CreateFile(L"D:\\file.txt", GENERIC_READ, 
                       FILE_SHARE_READ,
                       NULL,
                       OPEN_ALWAYS,
                       FILE_ATTRIBUTE_NORMAL,
                       NULL);
    
    	CString debug;
    
    	if (INVALID_HANDLE_VALUE == hFile){// if setting/file not valid
    		
    		debug = "Step 12";
    		detail.DetailValue = debug;
    	}
    detail.DoModal();
    i still can't access the file, it displays the step 12, anyone know why? thanks a lot!!

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,182
    Any reason you're using CreateFile instead of std::istream?

  8. #8
    Registered User
    Join Date
    Nov 2007
    Posts
    74
    coz i need to display the content in the dialog editbox

    can istream do this?

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,182
    Yes, and it's much simpler too. Not to mention pretty much the C++ standard.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > anyone know why?
    Well you could call GetLastError() to find out more information (like you did before).
    There's even an API to turn that error status into a string.

    Why did you use L"D:\\file.txt" and not TEXT("D:\\file.txt")
    The latter does the right thing whether you're compiling in ASCII mode or UNICODE mode.
    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.

  11. #11
    Registered User
    Join Date
    Nov 2007
    Posts
    74
    but how to display the getlasterror code?
    by the way i use the TEXT() function but no difference

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Why do you start the string with a backslash in the first place? A Windows path is "D:\...", not "\D:\...".
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #13
    Registered User
    Join Date
    Nov 2007
    Posts
    74
    coz ("D:\\") or ("\D:\\")makes no different in result and ("\D:\\") will get warnning

  14. #14
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    I'm not talking about escaped strings. I'm simply talking about Windows paths, outside the programming domain.

    But I see that in the later snippets, you dropped that initial backslash anyway.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  15. #15
    Registered User
    Join Date
    Nov 2007
    Posts
    74
    i have got the eror message from the getlasterror:

    the data area passed to a system call is too small

    but i dun understand, how can i fix it? thaknks!!

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 01:54 AM
  2. Adding a directory to a dynamic library path
    By vivharv in forum Windows Programming
    Replies: 3
    Last Post: 09-20-2007, 07:09 AM
  3. Accessing the 'home' directory path?
    By smoothdogg00 in forum C Programming
    Replies: 3
    Last Post: 04-30-2006, 10:51 AM
  4. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 08:43 AM
  5. File Input/Output Path Directory
    By tegwin in forum C++ Programming
    Replies: 7
    Last Post: 02-27-2002, 02:00 PM

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