Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-17-2005, 02:33 PM   #1 (permalink)
enemite
Registered User
 
Join Date: Sep 2004
Posts: 2
enemite is on a distinguished road
Send a message via AIM to enemite Send a message via MSN to enemite Send a message via Yahoo to enemite
Question get/change current directory in windows

I'm working on a flashcard program, and after you load a file and go through the drill, it will write your score/time to a text file. I also have a menu item that loads the text file with notepad like this:

ShellExecute(NULL, "open", "stats.txt", NULL, NULL, SW_NORMAL);

So after you have completed the flashcard set, it will write it to stats.txt file and then you can load it through the menu afterwards (and it's in the same directory as the file you have loaded).

But if you start the program and don't load a file and try to load the stats, it won't do anything because the current directory is still where the program itself is. And the stats you're trying to load are scattered wherever the cardset files are!

What I want to do write the stats file to the same directory the program itself is in so that it can always be loaded. And so there won't be a bunch of text files everywhere. Also it appends the stats to the same file so you can monitor your progress.

Looking at the prototype for ShellExecute() one of the parameters is for the default directory, but how do I change it and set it?

Is there a function to get the current directory the program is using?
And is there a function to change the current directory the program is using?

I've tried searching the web for info, but all I can find is help for VB, and I'm using C/C++. Can anyone help? And please go easy on me, it's my first post.
enemite is offline   Reply With Quote
Old 04-22-2005, 02:21 PM   #2 (permalink)
QUantumAnenome
Code Monkey
 
Join Date: Mar 2005
Posts: 55
QUantumAnenome is on a distinguished road
Send a message via Yahoo to QUantumAnenome
GetModuleFileName() will give you the exe you are currently running, and you can extract the directory from that.

If you have argv[0], that gives you the same thing.

If it's a windoze app, the equivalent of argv[] is available inside winmain() and you need to save it somewhere.

Also look at getcwd() - gets current working directory, chdir() - changes it, etc.
QUantumAnenome is offline   Reply With Quote
Old 04-22-2005, 09:36 PM   #3 (permalink)
enemite
Registered User
 
Join Date: Sep 2004
Posts: 2
enemite is on a distinguished road
Send a message via AIM to enemite Send a message via MSN to enemite Send a message via Yahoo to enemite
Thumbs up

Thanks! That's basically what I ended up doing. Just had to get the file name off the end. When I start the program and open a file, it will be in the last folder I opened a file from, even when I restart it. So I couldn't use GetCurrentDir() in the beginning because it wouldn't be in the right directory.

Ended up using SetCurrentDirectory() with the proper value. It works and that's all that matters. Going to try the getcwd() and chdir() though, just to see how they work.

By the way, you mentioned using argv[0], is there a way to find the number of arguments, too? Or are all the args just one string? And yeah, i'm using "Windoze". XP to be exact.
enemite is offline   Reply With Quote
Reply

Bookmarks

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembelly code register addressing toblerone Assembly 5 05-22-2006 02:53 AM
copy a directory link with -Rs sde Linux / BSD / OS X 3 02-15-2005 05:34 PM
Pirated software used to create help content in Microsoft's Windows XP sde Code Newbie News 3 11-17-2004 02:14 PM
The Windows of two minds creed Windows 4 11-10-2004 07:37 AM
Bloody Windows IE rendering sarah31 PHP 6 06-05-2002 07:31 PM


All times are GMT -8. The time now is 11:29 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting