![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: May 2006
Posts: 51
Rep Power: 3
![]() |
Relative File References
Hi,
I'm having trouble referencing files relativly. Here is my file structure: - BH
- System
*BH.exe (My application)
*Various.dlls
- Logs
*Error.log
*General.log
- Temp
*Database.mdbstring ErrorFile = @"..\Logs\Error.log"; StreamWriter sw = new StreamWriter(ErrorFile, true); I'd be very greatful if someone could point me in the right direction. Cheers
__________________
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit + Ubuntu 8.04 Intel C2D T5870 2.0GHZ -- Vostro 1510 -- 2048MB -- Windows XP SP2 ASCII stupid question, get a stupid ANSI ! |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 884
Rep Power: 4
![]() |
Re: Relative File References
You need to use \\ to put a backslash into a hard coded string in c++. Otherwise the \ character is used to escape the next character on.
string ErrorFile = @"..\\Logs\\Error.log"; Also note that the relative path is relative to the directory your program started in, which may not be the program's directory. If you are using a Window's shortcut to start the program, you can choose whichever directory you want. You might have to allow for this in your program. |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Re: Relative File References
This is C# and he used an @ in front of the string - so he doesn't need to escape anything.
Your second point is probably what's happened "Also note that the relative path is relative to the directory your program started in, which may not be the program's directory. If you are using a Window's shortcut to start the program, you can choose whichever directory you want. You might have to allow for this in your program."
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 884
Rep Power: 4
![]() |
Re: Relative File References
Oops, my bad - didn't notice the forum
![]() Maybe the second part of my reply is still valid. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CPP newbie, any way to make a call to a file for references? | Caitu | C++ | 1 | Jan 8th, 2008 11:03 AM |
| problem processing file into a char array | csrocker101 | C++ | 1 | May 9th, 2007 12:50 AM |
| After execution - Error cannot locate /Skin File? | wchar | Visual Basic | 1 | Mar 5th, 2005 10:04 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 5:12 PM |
| Structure char field to a disk file | ehab_aziz2001 | C++ | 0 | Feb 10th, 2005 3:42 PM |