Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > C++

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-07-2005, 02:52 PM
rssmps rssmps is offline
Registered User
 
Join Date: Oct 2005
Posts: 173
obtain current file directory

I'm currently using the following code to obtain the current directory.
is there a better C++ way of doing this? is there such a thing as #include <direct>?

Code:
#include <direct.h>

char buffer[_MAX_PATH];
/* Get the current working directory: */
if( _getcwd( buffer, _MAX_PATH) == NULL)
{
   cout<<( "_getcwd error on file" + filein );
   exit(0); 
} 
else
{
    path = buffer;  // path is string
}
also, for compatibility between unix and win, is there anythin in C++ such as the following in Java?
System.getProperty("user.dir")
System.getProperty("file.separator")

Thanks!

Last edited by rssmps; 10-07-2005 at 02:55 PM.
Reply With Quote
  #2  
Old 10-07-2005, 05:55 PM
Danny's Avatar
Danny Danny is offline
Super Moderator
 
Join Date: Nov 2003
Posts: 3,948
There's "dir.h" and "dirent.h" but they both use getcwd(). Alternatively, you can use the getenv() function to obtain the current directory, if you you its symbolic name:

const char * pdir= getennv("path");
__________________
Danny Kalev
Reply With Quote
  #3  
Old 10-07-2005, 06:10 PM
rssmps rssmps is offline
Registered User
 
Join Date: Oct 2005
Posts: 173
I'll give these a try....and report back if there are any problems.

for the code that I have above and the dir.h/dirent.h standard libraries, are these libraries win specific or standard across platforms?

Thanks!
Reply With Quote
  #4  
Old 10-07-2005, 08:22 PM
Danny's Avatar
Danny Danny is offline
Super Moderator
 
Join Date: Nov 2003
Posts: 3,948
they aren't officially standard but in practice, both Windows and POSIX systems support them, so they are pretty portable.
__________________
Danny Kalev
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 Off
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
directory listing to text file kgkidd VB Classic 2 09-19-2005 03:17 PM
Monitoring directory for new file and launch application Niklas E VB Classic 0 03-17-2001 01:47 PM
Send File object thru ObjectOutputStream ObjectInputStream Lim Wing Hoe Java 2 12-27-2000 05:22 AM
ASP creates HTML file, How can I get FrontPage to import it? Phil ASP.NET 3 05-31-2000 11:30 AM
Making a single jar file from differnet packages M.S.Ramagopal Java 0 05-02-2000 04:39 AM


All times are GMT -4. The time now is 09:58 PM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.