Author Topic: file access  (Read 3172 times)

Offline Maxheadroom

  • Mr. Drawsprite
  • **
  • Posts: 62
    • View Profile
    • http://www.hot-apartments.co.uk
file access
« on: 2005-Nov-23 »
Gernot,
   Can you help with a bit of code, I am trying to get the time into one of my programs, the code below works first time but when you run the code again it has not updated, Could it be that the file once accessed by Glbasic it will not close the file or "let go of the file for other programs", and when the dos shell trys to access it again it can't get access, If I am correct, are there any ways around it?.

Thanks, Maxheadroom.

Code:

Loop: // start

Shellcmd (“cmd /c time /t > tim.txt” ,true ,false, rv) // shell out and put time in tim.txt

Getfile “tim.txt”,0,time$ // open file and get the time

Print time$,100,100 // print time out on screen

showscreen

Goto loop // loop for ever

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10851
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
file access
« Reply #1 on: 2005-Nov-23 »
Ha!
Never thought of that! Really funny. I sat here, really stunned for a minute until it occoured to me what happened.
See, GLBasic uses an internal buffer for a file for read/write access. As long as you don't access another file, no disc-io is performed. That is a speed boost for usual tasks. Here, it's a problem.

I don't have a GLBasic here (Linux), but I guess this should work:

Code: (glbasic) [Select]
Loop: // start
   SHELLCMD (“cmd /c time /t > tim.txt” ,true ,false, rv) // shell out and put time in tim.txt
   GETFILE "", 0, time$ // flush the "tim.txt" file buffer, reopen "" (does not exist)
   GETFILE “tim.txt”,0,time$ // open file and get the time
   PRINT time$,100,100 // print time out on screen
   SHOWSCREEN
GOTO loop // loop for ever

Offline Maxheadroom

  • Mr. Drawsprite
  • **
  • Posts: 62
    • View Profile
    • http://www.hot-apartments.co.uk
file access
« Reply #2 on: 2005-Nov-23 »
time has been restored

Thanks all working! :D