Services Partners Company
Knowledge Base


Article

How to change the current working directory of a 4GL session on Windows?

« Go Back

Information

 
EnvironmentProduct: OpenEdge
Version: 10.x, 11.x
OS: All supported Windows
Question/Problem Description
How to change the current working directory of a 4GL session on Windows?
How to set the current working directory using 4GL at run time?
How to modify the current working directory of the Progress/OpenEdge 4GL/ABL session?
How to Call WIN32 API Function: SetCurrentDirectory
Steps to Reproduce
Clarifying Information
The working directory of the ABL client is fixed when the session starts, either by setting the "Start in:" directory in the Windows shortcut, or by changing to the directory in a startup script.

 
Error Message
Defect/Enhancement Number
Cause
Resolution

The following code sample shows how to invoke the Win32 API SetCurrentDirectoryW Function to change the current Working Directory of the 4GL/ABL session to: "C:\OpenEdge\WRK101B".

DEFINE VARIABLE iResult AS INTEGER NO-UNDO.

RUN SetCurrentDirectoryW (INPUT CODEPAGE-CONVERT("C:\OpenEdge\WRK101B", "UTF-16"), OUTPUT iResult).
IF iResult = 1 THEN MESSAGE "Current directory has been changed" VIEW-AS ALERT-BOX.
ELSE MESSAGE "Directory does not exist, or access is denied" VIEW-AS ALERT-BOX.

/* Define the entry point for the external DLL function */
PROCEDURE SetCurrentDirectoryW EXTERNAL "KERNEL32.DLL":
   DEFINE INPUT  PARAMETER chrCurDir AS CHARACTER.
   DEFINE RETURN PARAMETER iResult AS LONG.
END PROCEDURE.
SetCurrentDirectoryW is used instead of SetCurrentDirectoryA as it will handle extended characters in path names correctly. Note that it expects the pathname as a UTF-16 encoded string.
Workaround
Notes
Changing the working directory of a running process is considered bad practice as it is very likely to interfere with any file I/O that uses relative pathnames. The main use case for the code above is as a workaround if some other 3rd-party component in the environment changes the working directory unexpectedly.


References to Written Documentation:

OpenEdge Development, chapter: Programming Interfaces
000022094, How to obtain the working directory via the 4GL?
Attachment 
Disclaimer

The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.



Feedback
 
Was this article helpful?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful.



Characters Remaining: 255