Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 6th, 2008, 10:06 AM   #1
teishu
Programmer
 
Join Date: May 2006
Posts: 51
Rep Power: 3 teishu is on a distinguished road
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.mdb
I'm trying to access the Error.log file from BH.exe, i'm using the following:
string ErrorFile = @"..\Logs\Error.log";
StreamWriter sw = new StreamWriter(ErrorFile, true);
Can anyone see what is wrong with this ?

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 !
teishu is offline   Reply With Quote
Old Jun 8th, 2008, 5:49 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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.
The Dark is offline   Reply With Quote
Old Jun 9th, 2008, 12:04 AM   #3
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
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 !
xavier is offline   Reply With Quote
Old Jun 9th, 2008, 1:45 AM   #4
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Re: Relative File References

Oops, my bad - didn't notice the forum

Maybe the second part of my reply is still valid.
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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 10:03 AM
problem processing file into a char array csrocker101 C++ 1 May 8th, 2007 11:50 PM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 9:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM
Structure char field to a disk file ehab_aziz2001 C++ 0 Feb 10th, 2005 2:42 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC