473,480 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with Log File Creation

Hey,
I am trying to create log files in a different directory than where my
executable is at. I am pretty stumped. This is what I have in psuedo
code.

std::string const M_LOG_PATH = "\\data\\logs\\";
std::string m_log_filename_with_path;
std::string filename = "log.txt";

m_log_filename_with_path = M_LOG_PATH + filename;

std::fstream file;
file.open(m_log_filename_with_path.c_str());
file << "text" << std::endl;
file.close();

So....everything works but it creates the files in the same directory
as the executable and the whole file name ends up being "//data//logs//
log.txt" instead of log.txt in the //data/logs directory.

Can anyone help???

Oct 27 '07 #1
6 2241
subaruwrx88011 wrote:
Hey,
I am trying to create log files in a different directory than where my
executable is at. I am pretty stumped. This is what I have in psuedo
code.

std::string const M_LOG_PATH = "\\data\\logs\\";
std::string m_log_filename_with_path;
std::string filename = "log.txt";

m_log_filename_with_path = M_LOG_PATH + filename;

std::fstream file;
file.open(m_log_filename_with_path.c_str());
file << "text" << std::endl;
file.close();

So....everything works but it creates the files in the same directory
as the executable and the whole file name ends up being "//data//logs//
log.txt" instead of log.txt in the //data/logs directory.

Can anyone help???

File path names are system specific.

The "/" character works on most platforms (including recent windows
OS's) so why not try:
std::string const M_LOG_PATH = "/data/logs/"; ?
.... however, if you use the boost::file path name stuff or the Austria
C++ path name stuff, the "/" or "\" gets abstracted away and becomes OS
independant.

(The Austria filename stuff is in the netcabletv alpha).
Oct 27 '07 #2
On Oct 27, 5:03 pm, Gianni Mariani <gi4nos...@marian.wswrote:
subaruwrx88011 wrote:
Hey,
I am trying to create log files in a different directory than where my
executable is at. I am pretty stumped. This is what I have in psuedo
code.
std::string const M_LOG_PATH = "\\data\\logs\\";
std::string m_log_filename_with_path;
std::string filename = "log.txt";
m_log_filename_with_path = M_LOG_PATH + filename;
std::fstream file;
file.open(m_log_filename_with_path.c_str());
file << "text" << std::endl;
file.close();
So....everything works but it creates the files in the same directory
as the executable and the whole file name ends up being "//data//logs//
log.txt" instead of log.txt in the //data/logs directory.
Can anyone help???

File path names are system specific.

The "/" character works on most platforms (including recent windows
OS's) so why not try:

std::string const M_LOG_PATH = "/data/logs/"; ?

... however, if you use the boost::file path name stuff or the Austria
C++ path name stuff, the "/" or "\" gets abstracted away and becomes OS
independant.

(The Austria filename stuff is in the netcabletv alpha).
Sorry. I forgot to tell you guys.....this is on a Debian Linux
platform!!!!

Oct 28 '07 #3
subaruwrx88011 wrote:
....
Sorry. I forgot to tell you guys.....this is on a Debian Linux
platform!!!!
A linux system recognize "\\data\\logs" as being a simple file name -
not a directory path.
Oct 28 '07 #4
subaruwrx88011 wrote:
Can anyone help???
Maybe you should read all the replies in the other thread you started
because lots of people have already answered this question of yours.

Richard James
Oct 28 '07 #5
subaruwrx88011 wrote:
Hey,

Can anyone help???
Why ask basically the same question twice?

--
Ian Collins.
Oct 28 '07 #6
"subaruwrx88011" <su************@gmail.comwrote in message
news:11*********************@y42g2000hsy.googlegro ups.com...
On Oct 27, 5:03 pm, Gianni Mariani <gi4nos...@marian.wswrote:
>subaruwrx88011 wrote:
Hey,
I am trying to create log files in a different directory than where my
executable is at. I am pretty stumped. This is what I have in psuedo
code.
std::string const M_LOG_PATH = "\\data\\logs\\";
std::string m_log_filename_with_path;
std::string filename = "log.txt";
m_log_filename_with_path = M_LOG_PATH + filename;
std::fstream file;
file.open(m_log_filename_with_path.c_str());
file << "text" << std::endl;
file.close();
So....everything works but it creates the files in the same directory
as the executable and the whole file name ends up being "//data//logs//
log.txt" instead of log.txt in the //data/logs directory.
Can anyone help???

File path names are system specific.

The "/" character works on most platforms (including recent windows
OS's) so why not try:

std::string const M_LOG_PATH = "/data/logs/"; ?

... however, if you use the boost::file path name stuff or the Austria
C++ path name stuff, the "/" or "\" gets abstracted away and becomes OS
independant.

(The Austria filename stuff is in the netcabletv alpha).

Sorry. I forgot to tell you guys.....this is on a Debian Linux
platform!!!!
In linux / is the path seperator. \ is a valid character for a file name.
So you would definately want it:
std::string const M_LOG_PATH = "/data/logs/";
which should fix your problem.
Oct 28 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
9853
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
3
2261
by: SK | last post by:
I have a file. i get the creation time using File.GetCreationTime. then i go and delete that file. and then create it again and print the File.GetCreationTime. It is giving me the old creation...
2
3491
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an...
2
13177
by: Robizzle | last post by:
Sorry, I must be blind but I can't seem to find it anywhere. What function will return the time a file was created? I see filemtime(...) returns the time that file was last Modified and...
7
7657
by: Marius III | last post by:
Hi there, I want to get the file version of a file in PHP. Do somebody have the code for this? Thanks alot!
6
2854
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
6
4956
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
8
12280
by: Eddie Suey | last post by:
I want to add a new line to the begining of a text file. I dont want to write over existing data. How do I do this? the file is about 7 mb.
3
2011
by: Limunski Magarac | last post by:
Hi all :) My apologies if I posted in the wrong groups, but I just jumped in MS SQL waters, so any guidance will be appreciated. What I'm trying to do is the following process: present...
0
3151
by: SOI_0152 | last post by:
Hi all! Happy New Year 2008. Il hope it will bring you love and happyness I'm new on this forum. I wrote a stored procedure on mainframe using DB2 7.1.1 and IBM language c. Everything works...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7032
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.