Skip to Content

SetCurrentDirectoryA Doesn't Work

Jun 22, 2017 at 05:42 PM


avatar image

I'm trying to dynamically configure the working directory by calling the external kernel32 SetCurrentDirectoryA function, but no matter what I pass in as the path, it always seems to return false. What would make that happen? I'm using PB 12.6 classic on Win 10 desktop.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Chris Keating
Jun 22, 2017 at 06:46 PM

You have to declare the function such that PowerBuilder is treating the string as ANSI, i.e.,

FUNCTION long GetCurrentDirectory( long length , ref string path) LIBRARY "KERNEL32" ALIAS "GetCurrentDirectoryA;ANSI"

Alteratively, you could simply call GetCurrentDirectoryW as that would bypass the conversion.

10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jun 22, 2017 at 07:10 PM

Why not just use the PB directory function instead of calling the windows api?

also PB is moving on:


ChangeDirectory PowerScript function


Changes the current directory.


ChangeDirectory ( directoryname )



directoryname String for the name of the directory you want to set as the current directory

Return Values

Integer. Returns 1 if the function succeeds and -1 if an error occurs.


This example changes the current directory to the parent directory of the current directory and displays the new current directory in a SingleLineEdit control:

ChangeDirectory( ".." )
sle_1.text= GetCurrentDirectory( )

10 |10000 characters needed characters left characters exceeded