Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change Directory VC 6.0

Posted on 1999-07-14
15
Medium Priority
?
337 Views
Last Modified: 2011-09-20
I would like to write a console program using Vsual C++ 6.0 to change the current directory and exit staying in the new directory. I have tried chdir("\\new_dir") and _chdir("\\new_dir") and system("CD \\new_dir") but when they
end the directory is the one that I excuted the program in.
How can I accomplish what I want?
0
Comment
Question by:pentomino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 3

Expert Comment

by:Shay050799
ID: 1263587
check the return value of those functions, and make sure it succeeded, maybe the dir name u passing is bad, make sure if you pass '\' make it double '\\'
0
 
LVL 1

Author Comment

by:pentomino
ID: 1263588
Hi Shay

I have done all the things that you have mentioned.  My MIX power C does what I want, but not Visual C 6.0, and I want to use that compiler for long file name support.
0
 
LVL 3

Accepted Solution

by:
Shay050799 earned 200 total points
ID: 1263589
BOOL SetCurrentDirectory( LPCTSTR lpPathName   // pointer to name of new current directory
);
 
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:pentomino
ID: 1263590
Shay
Could you give me a short example.  An example  program to change the directory to C:\temp would be great.  (I have tried with no success)

Thanks
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1263591
SetCurrentDirectory("c:\\temp");

;-)
0
 
LVL 1

Author Comment

by:pentomino
ID: 1263592
Shay

I was thinking about a complete program that would compile in VC++ 6.0
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1263593
can i ask you why u need that ?
0
 
LVL 1

Author Comment

by:pentomino
ID: 1263594
Shay

Sure. I make a win32 consol program that uses MFC and tired using that function.
It compiled and ran but did not do what I wanted.  That function is a member of the
CFptConnecton class. (as far as I can tell) and it is not in the standard library (again as far as I know)..  So if you can get you small program to compile and work, I would be all set to continue my application.  I am tring to write a clone to nortons NCD (norton change directory) program that supports long files names.


0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1263595
u said that after u exit the application it still in the current directory, what do u care about the directory after you exit the application ?
0
 
LVL 1

Author Comment

by:pentomino
ID: 1263596
because the new directory is the one that I want to be in when the program stop.
That is the purpose of the norton change directory program. It give a graphic presentation of the directory tree, and then you select a directory to go to...


0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1263597
the thing is that the console application is closed after the application ends, do u want it to stay open or what ?
0
 
LVL 1

Author Comment

by:pentomino
ID: 1263598
I want to run the program in a dos window, under windows 98. In particular a full window.
0
 
LVL 9

Expert Comment

by:Pacman
ID: 1263599
Did you try SetCurrentDirectory from Win32 API?
pacman
0
 
LVL 1

Author Comment

by:pentomino
ID: 1263600
Pacman
No, I did not.  Can you provide an example, or tell me more details about how I would do that?
0
 
LVL 2

Expert Comment

by:hougaard
ID: 1263601
The NCD rely on the fact that all programs runs in the same address space.. When dealing with Windows (32bit) all programs are in seperate address space so from that perspective it would not be possible to do what you are asking...

My first solution would be something like this:

create a BAT like this

@echo off
YourProgram %1 %2 %3 %4 %5
call %TEMP%\Changeit.bat
del %TEMP%\changeit.bat

where changeit.bat would be a bat file that your program creates on exit with something like this in it:

F:
CD "\my documents\resumes\1999"


That would do the trick!




0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question