Page 1 of 1
Current Directory
Posted: Wed Feb 02, 2005 6:33 pm
by Polo
Hi !
Is it possible to get the current directory without using api ? Something which would be usable on linux and on windows ? I'm not sure if a PB function exist for this, i haven't see it

Thanks !
Posted: Wed Feb 02, 2005 7:47 pm
by dracflamloc
Well I'm not sure what you are using the current directory for, but to access files int he current directory you can open them such as this: "./example.txt"
Posted: Wed Feb 02, 2005 7:54 pm
by Polo
Wops

It's working, thanks ! (haven't tested it on windows, but i guess it's ok

)
Posted: Wed Feb 02, 2005 8:05 pm
by olejr
As dracflamloc said i'm not sure why you need to,
and I don't know about anything that is included in PB..
But it's not hard to do it with API either:
Drop this into your code, and it work on both Linux and Windows.. (Not Amiga, but you didn't ask for it so..)
Code: Select all
; Procedure that return CurrentDir as String
Procedure.s GetCurrentDirectory()
currentdir.s = Space(255) ; <- 255 is defined as #MAX_PATH in Window, not Linux, oh well.
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
getcwd_(@currendir, 255)
If Right(currentdir, 1) <>"/" : currentdir + "/" : EndIf
CompilerElse
GetCurrentDirectory_(255, @CD)
If Right(currentdir,1)<>"\" : currentdir + "\" : EndIf
CompilerEndIf
ProcedureReturn currentdir
EndProcedure
Posted: Wed Feb 02, 2005 8:17 pm
by Polo
Thanks Olejr !! I'll use this if Dracflamloc's trick don't work on linux, but it's working on windows, so...

BTW, its for using with :
RunProgram
when using parameters, we must put the current directory (strange ??), but puting "./" on windows is working well and is probably the fast way, and i guess it works with linux too, i'll test tomorrow

Posted: Wed Feb 02, 2005 8:20 pm
by olejr
Yes the "./" should also work on Linux..
Little tip:
You can also use "../" to get to the parent dir..
So if you need to go 2 dir's back and into some other it's like:
"../../path-to-what-ever"