How to check to see if a file exists without mounting a volume

I keep list of folderItems that are the locations where I have stored PDFs, and when given a PDF name cycle through them to find in which folder the PDF resides. Some of the folders are on mounted servers. The problem is that if the volume is unmounted my app will try to mount it (folderPath = GetFolderItem(thefolderpath)). This can cause long delays and timeouts if the server is unavailable. I’d like to check to see if the server/folder is available and, if not, avoid the call to GetFolderItem. I tried using folderPath = new folderItem() but it, too, tries to mount the volume.

you’d have to walk through the path and see if

  1. the volume is mounted - does Volume(X) have that same name ?
  2. if there is such a volume mounted then use getfolderitem

Note that OS X can have several volumes with the same name but can distinguish so (1) is not 100% reliable

Thanks Norman, that should do the trick. To add a small complication, the folderItems are stored as aliases. I don’t see an obvious way to create a folderItem (so I can get the volume name) without triggering the mount.

You may want to cache the file structure while the drive is mounted, and then explore that structure instead of the actual drive. At first glance, I would be inclined to use a database for the search feature, possibly in memory, especially if the drive contains many files and folders.

No if they are stored as aliases you wont have any option
It will just try to resolve the alias which means trying to mount the folder with whatever dialogs about not finding the volume along the way

you can store aliases, e.g. with MacAliasMBS class.
We also have an AliasInfoMBS class to give you details like file path.

And the plugin can find the file and you specify if mounting or dialogs are allowed.

Thanks all.

[code] Dim s As New shell
Dim L As String
Dim SQ As String = chr(34)//quote
L = "mount |grep " +sq +volumeName +sq
s.Execute(L)

If s.ErrorCode = 0 Then
msgbox “Volume exist”
Else
MsgBox(“Failed to find the Volume !!”)
End If[/code]

One more

[code]Dim n as integer
Dim VolumeName,ImageName as string
ImageName =name // <<< “here the volume name you looking for”
n=volumecount -1

For i = 0 To n
VolumeName = Volume(i).Name
If VolumeName = ImageName Then
MsgBox “Volume exist !!”
else
“do what you want”
End If

Next[/code]

One more maybe is

$ du -sh * 32M Desktop 217M Documents 531M Downloads 12G Library 5.2G Movies 2.1G Music 1.5G Pictures 8.0k Public 36k Sites

If you use the shell command (first example) as class and mode 2 is async mode so you get the results without affect the app.

This is probably one of the few times that I’d actually recommend the disgusting filth that is a Security-Scoped Bookmark. For the pure and simple reason that you can tell it to not mount a volume when trying to resolve. Make sure you were big thick rubber gloves and bathe in borax afterwards…