Thread: File path problems

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    3

    File path problems

    I'm using the CreateFile() function from win32 to open a file. it works ok when I include the full path to the file but fails when I just use the name of the file which is located in the same directory as the debug exe. I'm using VC++ 6.

    Code:
     
    FileHandle = CreateFile("C:\\Documents and Settings\\Dannyboy\\My Documents\\ICC Programmer project\\FileWizard\\Debug\\Extensions.csv", GENERIC_READ | GENERIC_WRITE, 0, NULL, 
    		                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    this is ok but this fails:

    Code:
    FileHandle = CreateFile("Extensions.csv", GENERIC_READ | GENERIC_WRITE, 0, NULL, 
    		                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    thanks

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by drclark View Post
    I'm using the CreateFile() function from win32 to open a file. it works ok when I include the full path to the file but fails when I just use the name of the file which is located in the same directory as the debug exe. I'm using VC++ 6.
    That's because even though that is where the exe is stored it is not the default working directory for the project. Move the file to the FileWizard Directory (whatever directory your .c file is actually located).
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL_LoadBMP file path...
    By manugarciac in forum C++ Programming
    Replies: 2
    Last Post: 04-26-2007, 07:16 AM
  2. Getting file name off path
    By cgod in forum C++ Programming
    Replies: 6
    Last Post: 09-22-2005, 10:45 AM
  3. shortest path problems
    By talz13 in forum C++ Programming
    Replies: 7
    Last Post: 05-08-2004, 06:13 AM
  4. Path problems
    By pdstatha in forum C Programming
    Replies: 0
    Last Post: 03-28-2002, 07:10 AM
  5. getting a file's path and filename
    By face_master in forum Windows Programming
    Replies: 4
    Last Post: 02-05-2002, 01:44 PM