NIL OBJECT EXCEPTION on folderitem.item

Hi!

I’m using macOS Catalina and Xojo 2018 R1.1
I’m interacting with a folder with 3 items.

when i “ls -lah” the folder i got:

rw-r–r-- 1 alemac staff 1.5M Jan 28 19:00 # mytest.pdf
drwxr-xr-x@ 5 alemac staff 160B Mar 18 18:00 .
drwx------+ 11 alemac staff 352B Mar 18 17:59 …
rw-r–r--@ 1 alemac staff 681M Jan 28 18:59 mytest.dmg
rw-r–r--@ 1 alemac staff 495M Jan 28 19:01 mytest.rar

so… 3 items: one pdf, one dmg and one rar file.

when I debug the “command” string variable:

for i=1 to pasta.Count
  command = pasta.item(i).name
  tipoDeArquivo = right(pasta.item(i).name,3)
  if tipoDeArquivo = "dmg" then
     f = pasta.item(i)
     command = "hdiutil attach -noverify " + f.ShellPath
     s.Execute(command)
     exit
   end if
next

command = pasta.item(i).name when i=1… mytest.rar
command = pasta.item(i).name when i=2… # mytest.pdf
command = pasta.item(i).name when i=3… NIL OBJECT EXCEPTION!

Why???

0 based? Try

for i = 0 to pasta.Count - 1

It’s one based, not zero:

Sorry about that. I don’t have Catalina or 2018r1.1, I did a test on a 3 item folder and your code works correctly in Mojave and 2019r1.1

Maybe a problem with the macOS and Xojo version. Can you try a different combination? Newer Xojo?

You might try 2019r3.1 using the new FolderItem.ChildAt method. If that also gives you a NOE, then I would report it. Just remember that ChildAt is zero-based. :slight_smile:

Try pasta.TrueItem(i).Name …

Nota: I do not know if item #3 is a link (alias) or not. If it is, it may be off line at that project run time, who knows ?

I can’t tell you why, but for many years when using folderitem.item or folderitem.trueitem, you’ve had to test for Nil.

My guess has been that it’s a permissions thing (probably ACL) that prevents you from even knowing that there’s a file there. from your listing I can see that Mytest.dmg has ACLs present.

Try the following two lines in the terminal.

xattr -c mytest.dmg chmod -755 mytest.dmg
These should reset all the permissions on the file. You may have to sudo first.

Let me know if it makes any difference.

[quote=479633:@Emile Schwarz]Try pasta.TrueItem(i).Name …

Nota: I do not know if item #3 is a link (alias) or not. If it is, it may be off line at that project run time, who knows ?[/quote]

it’s a real file, not a hard link, not an alias.

[quote=479635:@Sam Rowlands]I can’t tell you why, but for many years when using folderitem.item or folderitem.trueitem, you’ve had to test for Nil.

My guess has been that it’s a permissions thing (probably ACL) that prevents you from even knowing that there’s a file there. from your listing I can see that Mytest.dmg has ACLs present.

Try the following two lines in the terminal.

xattr -c mytest.dmg chmod -755 mytest.dmg
These should reset all the permissions on the file. You may have to sudo first.

Let me know if it makes any difference.[/quote]

did xattr and chmod. same error

if I do:

f=GetFolderItem(f.parent.Child(replace(f.name,"rar","dmg")).ShellPath,folderitem.PathTypeShell)

it works.

the error is only if I interact using pasta.item(i)

Try:

System.Log pasta.item(i).NativePath

[quote=479644:@Emile Schwarz]Try:

System.Log pasta.item(i).NativePath[/quote]

sorry… this is the correct syntax?

Yes, read:
http://documentation.xojo.com/api/files/folderitem.html

Of course, if pasta.item(i) holds a FolderItem.

[quote=479662:@Emile Schwarz]Yes, read:
http://documentation.xojo.com/api/files/folderitem.html

Of course, if pasta.item(i) holds a FolderItem.[/quote]

I’m asking about this syntax…
System.Log pasta.item(i).NativePath

And that is to that question I responded.

You meant System.DebugLog. A simple search in the documentation would spotted the error: I was 25% awake :frowning: and forgot the Debug part. I checked FolderItem (to be sure it still exists in API2), but forgot to do so for DebugLog.

Sorry.

Also, as a Computer user, you know that asking indefinitely the same question will returns the same answer. Now that I slept for so many hours, I can spot the error. From your point of vie, you have copy/paste the provided code and get the error in Xojo. You alse spotted the error to System.Log (because you set "pasta.item(i).NativePath" between quotes). Don’t you think ?

Once more, sorry for the error.

[quote=479690:@Emile Schwarz]And that is to that question I responded.

You meant System.DebugLog. A simple search in the documentation would spotted the error: I was 25% awake :frowning: and forgot the Debug part. I checked FolderItem (to be sure it still exists in API2), but forgot to do so for DebugLog.

Sorry.

Also, as a Computer user, you know that asking indefinitely the same question will returns the same answer. Now that I slept for so many hours, I can spot the error. From your point of vie, you have copy/paste the provided code and get the error in Xojo. You alse spotted the error to System.Log (because you set "pasta.item(i).NativePath" between quotes). Don’t you think ?

Once more, sorry for the error.[/quote]

system.DebugLog(pasta.item(i).NativePath)
out of bounds on first iteration (i=0)…

Why do you change that ?

The docs says:

If this FolderItem is a directory, Index is an element in a one-based array of FolderItems in this directory.

And you wrote earlier:

[quote=479733:@Emile Schwarz]Why do you change that ?

The docs says:

If this FolderItem is a directory, Index is an element in a one-based array of FolderItems in this directory.

And you wrote earlier:[/quote]

This is the code:

for i=1 to pasta.Count command = pasta.item(i).name tipoDeArquivo = right(pasta.item(i).name,3) if tipoDeArquivo = "dmg" then f = pasta.item(i) command = "hdiutil attach -noverify " + f.ShellPath s.Execute(command) exit end if next

when the for i=3 on this code above, I get a NIL OBJECT EXCEPTION!

Exactly which line gives you the exception?

Is it: command = pasta.item(i).name

… or some other line.

What kind of volume is “pasta” on? It it shared?

when the i=3 in the for next loop

In the code below (El Capitan, Xojo 2015r1).

I set three files in the “Dossier” folder, and pasta.Count = 4 (3 items and 1 invisible file).
The first file extension is “ore” (from the invisible file .DS_Store).

First run with a dmg file works fine. I checked what does hdiutil attach and added a dmg in the folder.
Nota: that (new) folder does not have invisible file(s).

I hope this help you.

The run crash sometimes, but not always.

[code] Dim pasta as FolderItem
Dim f as FolderItem
Dim command As String
Dim i As Integer
Dim tipoDeArquivo As String
Dim s As New Shell
pasta = GetFolderItem(“Dossier”)

for i=1 to pasta.Count
command = pasta.item(i).name
tipoDeArquivo = right(pasta.item(i).name,3)
if tipoDeArquivo = “dmg” then
f = pasta.item(i)
command = "hdiutil attach -noverify " + f.ShellPath
s.Execute(command)
exit
end if
next[/code]