CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

OFstream doesnbt create directories or throw errors

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By niklas

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 26, 2006, 18:53
Default In the code that I'm currently
  #1
brooksmoses
Guest
 
Posts: n/a
In the code that I'm currently writing, I've got a couple of lines approximately like the following:

fileName myFile = mesh.time().rootPath() / "output" / "datafile.dat";
OFstream myStream(myFile);
myFile << "Test!" << endl;

If the "output" directory exists, this works perfectly; the file gets created and written to just as I expect.

However, if the "output" directory does not exist, then the code silently ignores my requests -- it does not create an "output" directory, nor does it throw an error about the absence of the directory or give any indication that it isn't actually writing anything.

Is there any way to tell OFstream to create the directory? Or at least to throw an error if the directory doesn't exist? If not, what's the best way to have my code create the directory?

Thanks!
  Reply With Quote

Old   January 27, 2006, 02:28
Default just add mkDir before writing
  #2
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
just add mkDir before writing

fileName myDir = mesh.time().rootPath()/"output";
mkDir(myDir);
fileName myFile = myDir/"datafile.dat";
OFstream myStream(myFile);

N
Michael@UW likes this.
niklas is offline   Reply With Quote

Old   January 27, 2006, 21:18
Default Thanks much! Thats just what
  #3
brooksmoses
Guest
 
Posts: n/a
Thanks much! Thats just what I needed.
  Reply With Quote

Old   January 30, 2006, 06:28
Default For future reference, take a l
  #4
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21
eugene is on a distinguished road
For future reference, take a look at OSspecific.H and/or Unix.C for the available system commands.
eugene is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SetFields runs with no errors but doesnbt change fields adamsview OpenFOAM Pre-Processing 3 December 12, 2014 21:03
A problem about class OFstream jennyrui2008 OpenFOAM Running, Solving & CFD 0 December 5, 2008 03:55
particles in water throw a porous media marion FLUENT 1 May 31, 2007 12:58
Condensation models- Can someone throw some light Saurav FLUENT 0 October 21, 2005 14:23
Throw some light on FLUIDYN commercial CFD package Anis-ur-Rehman Main CFD Forum 0 January 24, 2001 01:35


All times are GMT -4. The time now is 01:13.