Help with reading file on USB key

I have the following in the Open Event of my app:

  Dim i, n, Vol as Integer
  Vol = -1
  n= VolumeCount - 1
  For i = 0 To n
    If Volume(i).Name = "CLASSES" Then
      Vol = i
    End If
  Next
  
  If Vol = - 1 Then
    MsgBox("Please insert the supplied EMTEC USB Key!")
    Quit
  End If

This works fine on the Mac (Yosemite).

In the LR I cannot see that there is a difference between Windows and the Mac, but on Windows, the Message Box comes up with the error.

I am using the USB key to store a database which records certain things from the running program in case of a system crash. I do suppose that I could store it on the Windows box, but I need to be very cautious in case there may be a disk crash (remote I know) but hours of time would be lost if they program had to be restarted from scratch. With the recorded information I could quickly get another computer up to date with where the process is.

Thanks in advance.

[quote=138396:@Cliff Strange]I have the following in the Open Event of my app:

  Dim i, n, Vol as Integer
  Vol = -1
  n= VolumeCount - 1
  For i = 0 To n
    If Volume(i).Name = "CLASSES" Then
      Vol = i
    End If
  Next
  
  If Vol = - 1 Then
    MsgBox("Please insert the supplied EMTEC USB Key!")
    Quit
  End If

This works fine on the Mac (Yosemite).

In the LR I cannot see that there is a difference between Windows and the Mac, but on Windows, the Message Box comes up with the error.

I am using the USB key to store a database which records certain things from the running program in case of a system crash. I do suppose that I could store it on the Windows box, but I need to be very cautious in case there may be a disk crash (remote I know) but hours of time would be lost if they program had to be restarted from scratch. With the recorded information I could quickly get another computer up to date with where the process is.

Thanks in advance.[/quote]

In Windows, volume.name appear as letters :

C: D: E: F: G: H: I:

You will never find any volume called “CLASSES” that way…

To avoid more complex code, declares, etc and as you are in charge of the USB stick content, then perhaps you could look for the existence of a specific file existing on the volumes.

How would one go about determining the name of the USB stick on Windows?
If Volume returns a FolderItem, but Volume.Name returns the drive letter where would we find the actual name?

Tim,

Have a look at the last entry to https://forum.xojo.com/6556-is-it-possible-to-get-a-volume-type-on-windows

And also http://msdn.microsoft.com/en-us/library/aa243206(v=vs.60).aspx

The Windows OLE object FileSystemObject has a Volume property that should give you what you want.

Patrick

I believe the windows functionality suite has code for getting volume names
https://github.com/arbp/WFS

[quote=138445:@Tim Parnell]How would one go about determining the name of the USB stick on Windows?
If Volume returns a FolderItem, but Volume.Name returns the drive letter where would we find the actual name?[/quote]

Getting the disk label requires a declare :frowning:

Thanks for all the replies, amazing sometimes what a new day brings :slight_smile:

I would rather not go down the road of Declares at the moment. It seems to me that the problem with Volume letters is that I probably don’t know what that might be on different computers. In my Parallels virtual windows7 partition it is E: but that probably may not be the case on another computer? Also, if I can determine the volume letter somehow, will it then always be be same for a USB stick? Would it, for instance, change if it were put into a different port? probably yes.

So in the meantime I am going to try Chris’ suggestion of checking each volume for the existence of the sqlite file I know is on the stick.

Windows sets the letter C: for the boot, then a following letter for whatever comes. D for another hard disk, or the memory stick for instance. My machine goes up to I at the moment.

Checking for a file is the most sensible way to go.

Thanks Michel.

The program that I am creating is destined for use on the PC, so it is good to know that I should be able to make this work. It also kills two birds with one stone - if I can find the file, then I can also open it immediately.

Once again, thanks for all replies.

Checking for the existence of the database file worked on both the Mac and the PC.

Here is my code:

[code] Dim i, n, Vol as Integer
Vol = -1
n= VolumeCount - 1
For i = 0 To n
Dim dbFile As FolderItem = (Volume(i).Child(“checkDatabase”).Child(“MyDb.sqlite”))
If dbFile <> Nil Then
If dbFile.Exists Then
Vol = i
End If
End If
Next

If Vol = - 1 Then
MsgBox(“Please insert the supplied EMTEC USB Key!”)
Quit
End If
[/code]

The only difference to my original setup was I had to put the database file in a folder instead of just on the USB key. Not big deal, although a little confusing as to why.

Just did a quick test on Windows (only), using a USB stick with a dummy file called MyDb.sqlite and the above code, except for the folderitem line being…

Dim dbFile As FolderItem = (Volume(i).Child("MyDb.sqlite"))

and it found the file OK

Hmm,

I’ll have another go. Perhaps I misspelled the file name. I would be happy to have just the file on the USB stick.

Thanks Chris

[quote=138471:@Norman Palardy]I believe the windows functionality suite has code for getting volume names
https://github.com/arbp/WFS[/quote]

The method is part of the module FileProcessingWFS and is called adequately GetVolumeName :wink: