Ram drive

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Chevron.

Would it be possible to create a temp. ram drive using purebasic that could then be accessed with the "d:\" syntax from withiun a PB program.

Thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Would it be possible to create a temp. ram drive

I assume you mean for Windows, because the Amiga already has one! :)

Maybe something here can help you:

http://groups.google.com/groups?q=create+ramdisk+vb

If not, can I ask for what reason? Is it because you need to create
temp files that the user isn't supposed to see? If so, then just
create them in the Windows temp folder and delete them afterwards.
This works even if your app is run off a CD-ROM or write-protected
floppy disk. You do it like this:

Code: Select all

; Get Windows temp folder location.
tmpdir$=Space(255) : GetTempPath_(255,tmpdir$)
If Right(tmpdir$,1)"\" : tmpdir$=tmpdir$+"\" : EndIf
;
; Create a temporary file in it (without overwriting any existing files).
Repeat
  tmpfile$=tmpdir$+"MyAppName"+Str(Randomize(9999)) ; Make up a random file name.
Until FileSize(tmpfile$)=-1 ; And more sure it doesn't exist before creating it.
;
; Now create tmpfile$ and do whatever you want with it.
If CreateFile(0,tmpfile$)
  ; Write whatever here.
  CloseFile(0)
  ; Maybe even mark it as "Hidden" if you really want.
  SetFileAttributes_(tmpfile$,#FILE_ATTRIBUTE_HIDDEN)
EndIf
;
; Remember to delete it when done, and/or when your app ends (very important!).
DeleteFile(tmpfile$)

PB - Registered PureBasic Coder
Post Reply