Solved

How to change current dir

Posted on 2001-09-06
8
494 Views
Last Modified: 2010-04-06
After the current directory has been changed by selecting a file using an Opendialog how can I change it back to the dir where the program is.... the dir of application.exename  ?

begin
OpenDialog1.Execute;
MyStream.SaveToFile(OpenDialog1.Filename);
//now how do I set current dir back
//to the programs dir so that the following line
//saves another copy of MyStream as 'test.txt'
//in the same dir that the program is in
MyStream.SaveToFile('test.txt');
end;

0
Comment
Question by:Gwena
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 

Expert Comment

by:pin_plunder
ID: 6462721
// this saves the file test.txt in the dir where the executable is stored
MyStream.SaveToFile(ExtractFilePath(Application.ExeName) + 'test.txt');
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6462741
this is how you get the dir of the current executable

ExtractFilePath(Application.ExeName);

e.g.

if OpenDialog1.Execute then
begin
  MyStream.SaveToFile(OpenDialog1.FileName);
  MyStream.SaveToFile(ExtractFilePath(Application.ExeName) + 'Test.txt');
  // or if you want to save it with the same name as in OpenDialog1, but in different path:
  MyStream.SaveToFile(ExtractFilePath(Application.ExeName) + ExtractFileName(OpenDialog1.FileName));
end;


Hope that helps!



DragonSlayer.
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6462748
oops pin_plunder, I opened too many EE windows, and did not refresh 'em... hence I did not see your comments and posted mine instead... sorry! :)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Author Comment

by:Gwena
ID: 6462810
Hi :-)
  Yup.. I know how to save a file to the same dir as the executing program... what I'd like to know is how to set the default dir back to the dir of the exe... just as though the opendialog had never changed it at all... so that the code
MyStream.SaveToFile('test.txt');
Will save test.exe in the same dir as the exe...even after opendialog has executed.

I'd like to do what this code looks like it could do (but can't)

current.directory := ExtractFilePath(Application.ExeName);
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6462847
Perhaps this is what you are looking for.

ChDir(ExtractFilePath(Application.ExeName));
0
 
LVL 44

Accepted Solution

by:
CrazyOne earned 150 total points
ID: 6462851
Or perhaps this

SetCurrentDir(ExtractFilePath(Application.ExeName));

Delhi Help says

Sets the current directory.

Unit

Sysutils

Category

file management routines

function SetCurrentDir(const Dir: string): Boolean;

Description

The SetCurrentDir function sets the current directory. The return value is True if the current directory was successfully changed, or False if an error occurred.
0
 
LVL 5

Author Comment

by:Gwena
ID: 6462973
Thanks CrazyOne :-)
  That works perfectly! exactly what I was looking for :-)

gwen..
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6462979
You are welcome qwena :>)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

623 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