Le 7 oct. 06 à 18:01 Soir, Terry Ford a écrit:
On Oct 7, 2006, at 8:32 AM, Arnaud Nicolet wrote:
The volume function takes an integer for its parameter (that's life).
If you want to look for your disk, you may use:
dim f as folderItem
dim i as integer
for i=0 to VolumeCount-1
f=Volume(i)
if f<>nil and f.name="My Files Hard Drive" then exit
next
if f=nil then
MsgBox "The disk “My Files Hard Drive” has not been found."
'Show SelectFolder dialog or retry
return 'If you don't do anything, at least put a return
end if
Then 'f' is your disk.
Note that, if you have more than one disk named "My Files Hard
Drive", the first one you inserted will be used.
You are correct. One should also check, individually, for the
Children as well to ensure the path is complete.
You are right.
Also, we could construct an array of all volumes having the correct
name (on Mac, there can be several) and, by checking the Children,
removing the volumes where the path does not exist (so if the wanted
disk is the second one named as we want, the code does not fail).
I'd imagine something like that:
dim f As FolderItem
dim Folders(-1) As FolderItem
dim i As integer
dim j As integer
dim s As String
dim SubFolders(-1) As String
j=VolumeCount
for i=0 to j
f=volume(i)
if f<>nil and f.name="My Files Hard Drive" then
Folders.append f
end if
next
'Folders contains every volume that has this name
if UBound(Folders)=-1 then return 'No disk at all with that name
SubFolders.Append "My docs"
SubFolders.Append "My New docs"
for j=0 to UBound(SubFolders)
s=SubFolders(j)
for i=UBound(Folders) downto 0
f=Folders(i).Child(s)
if f=nil or not f.Exist then
Folders.Remove i
else
Folders(i)=f
end if
next
next
Select Case UBound(Folders)
case -1
'Apparently, no disk contained the wanted path
return
case 0
f=Folders(0) 'A single volume is correct
else
'Several volumes named correctly have the correct subfolders.
'"Rand" is a property of the app class, of type Random
i=Rand.InRange(0,UBound(Folders))
f=Folders(i) 'So choosing a random one (well...)
end select
'use f
May contain mistakes, but I won't install a second hard disk and make
the same subfolders to test it ;-)_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>