I have a folder called “Images”, and inside are two images.
When I try to get a list of the files inside “Images” the file count is always zero.
How do I get a file list of inside the a folder in SpecialFolder.Documents?
The code below always tells me there’s no files inside the folder.
Var f As FolderItem = SpecialFolder.Documents.Child("Images")
Var file As FolderItem
Var a As String
If f.IsFolder Then
a = a + "It is a folder." + EndOfLine
End If
Var fileCount As Integer = f.Count
a = a + "Has " + fileCount.ToString + " files." + EndOfLine
For i As Integer = 1 To fileCount
file = f.ChildAt(i)
If file <> Nil Then
a = a + file.Name + EndOfLine
End If
Next
MessageBox (a)
How did the images get there?
Is this on a device or the simulator?
The documents folder you are reading may not be the one you put the images into… it certainly wont be the normal one on your mac if this is running in the simulator
I found the answer. You have to list all the files in the SpecialFolder.Documents folder, and not any child folders.
This will not work:
Var f As FolderItem = SpecialFolder.Documents.Child("Images")
This will work
Var f As FolderItem = SpecialFolder.Documents
The code below will list all files and folders in the iOS app’s Documents folder. Files inside folders will have colons in the file name to show what folder they’re in, i.e. “Images:Flowers”
Var f As FolderItem = SpecialFolder.Documents
Var file As FolderItem
Var a As String
Var fileCount As Integer = f.Count
For i As Integer = 0 To fileCount - 1
file = f.ChildAt(i)
If file <> Nil Then
If Not file.IsFolder Then
a = a + file.Name + EndOfLine
Else
a = a + file.Name + " is a folder" + EndOfLine
End If
End If
Next
MessageBox (a)
I have a text file called StoreName, a folder named Images, and two pictures inside that folder (Waterfall, Flowers)
I’m still suspicious… that doesn’t look right.
What code do you use to save the images ’ in ’ the Images folder?
Are you building a file path using absolute or nativepath and adding the image name to that?
I normally use
var f as folderitem
For Each f In SpecialFolder.Documents.Children
I dont use a sub folder personally, but it looks to me like your ‘child’ records are just oddly named children of documents.
Indeed, this syntax won’t create a subfolder. “/” is actually a valid character in a Mac filename (try in Finder if you want), which is sometimes shown as “:”, as you’ve discovered.