[Implemented] GetCurrentDirectory()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

[Implemented] GetCurrentDirectory()

Post by naw »

Hi,
It appears that the only way to get the Current Working Directory name is like this:

Code: Select all

curPath.s=Space(#MAX_PATH)
GetCurrentDirectory_(#MAX_PATH,@curPath)
curPath+"\"
- which is fine, but only available for Windows. Can we please have a legitimate X-Platform PB command to do the same
Ta - N
phillip
New User
New User
Posts: 4
Joined: Sat Dec 10, 2005 7:11 am

Determine the current working directory

Post by phillip »

If your using linux you can always write the envirorment varable to the file, open and read the varable. Just type export to find it.

Phillip Taylor
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

Hi Phillip,
- Yes thats a good idea. But for sucha simple function, it would be nice to have a native PB command. That would cross-compile.
Ta - N
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

You can use this:

Code: Select all

Procedure.s GetCurrentDir()
  Protected CurDir.s
  CurDir.s = Space(2048)
  CompilerIf #PB_Compiler_OS = #PB_OS_Linux
    getcwd_(CurDir, 2048)
  CompilerElse 
    GetCurrentDirectory_(2048,CurDir)
  CompilerEndIf
  ProcedureReturn CurDir
EndProcedure

Debug GetCurrentDir()
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply