CurrentDir() with solution code
Posted: Fri May 09, 2003 9:34 pm
This command appears to be missing from PB's extensive command list, but in case anyone needs it, you can do it this way:
Works pretty good!
Here's a quick WaitMouse() and WaitKey() also (I missed these):
WaitMouse() and WaitKey() halt program execution until a mouse click or a keypressed is detected (respectively). Unfortunately, they only work in OpenScreen() mode or OpenWindowedScreen() mode.
Hope this helps someone.
Russell
_________________
*** 6510: If it were 32 bits wide and ran at todays clockspeeds... would it beat a Pentium 4? ***
Code: Select all
Procedure.s CurrentDir()
; This is the 'safe' version (Find out how big the buffer is first). A slightly less safe, but faster version would be:
; sDir = Space(1000) ; Safe as long as the actual path is not longer than the size of sDir
; If GetCurrentDirectory_(1000,@sDir)
; ProcedureReturn sDir
; Else
; ProcedureReturn ""
; Endif
sDir.s = " " ; Local variable
BuffSize.l = GetCurrentDirectory_(2,@sDir) ; Guaranteed to fail, but the return value is the required buffer length...
If BuffSize = 0 ; ...unless there was a REAL error (couldn't read dir, etc)
ProcedureReturn "" ; Couldn't get the directory path
EndIf
sDir = Space(BuffSize) ; So now we can re-call it with the correct size:
BuffSize = GetCurrentDirectory_(BuffSize,@sDir); And sDir contains the current full path (minus "\" at the end)
If BuffSize: ProcedureReturn sDir: Else: ProcedureReturn "": EndIf
; We could have written this procedure with the string to be modified as the parameter (via a pointer), but the return
; style is more like other other languages and probably easier to understand.
EndProcedure
Works pretty good!
Here's a quick WaitMouse() and WaitKey() also (I missed these):
Code: Select all
Procedure WaitMouse()
; InitMouse() must be called before calling this procedure
While MouseButton(1) = #FALSE And MouseButton(2) = #FALSE And MouseButton(3) = #FALSE
ExamineMouse()
Wend
EndProcedure
Procedure WaitKey()
; InitKeyboard() must be called before this procedure
Repeat
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_All)
EndProcedure
WaitMouse() and WaitKey() halt program execution until a mouse click or a keypressed is detected (respectively). Unfortunately, they only work in OpenScreen() mode or OpenWindowedScreen() mode.
Hope this helps someone.
Russell
_________________
*** 6510: If it were 32 bits wide and ran at todays clockspeeds... would it beat a Pentium 4? ***