leeladhar
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2010
08:40 PM
How to check if a file exists in roku
Hi,
I am using SimplePoster.brs, How can we achieve below functionality.
From XML Feed, I get an image name, I want to check whether that file exists, if it doesn't exist then i need to show a default image
This is what i want to do, how to check the file_exists functionality in BrightScript ?
if(file_exists(currShow@hdImg))
Item.hdImg = validstr(currShow@hdImg)
else
Item.hdImg = "pkg:/images/default.png"
end if
For now when I try to use an non exisitng file name i am getting error, ***ERROR: Missing or invalid PHY
After searchng forums, i got to know that we can do error_handling using Eval(), but can some one explain how to use it in above scenario ?
Thanks
Leeladhar
I am using SimplePoster.brs, How can we achieve below functionality.
From XML Feed, I get an image name, I want to check whether that file exists, if it doesn't exist then i need to show a default image
This is what i want to do, how to check the file_exists functionality in BrightScript ?
if(file_exists(currShow@hdImg))
Item.hdImg = validstr(currShow@hdImg)
else
Item.hdImg = "pkg:/images/default.png"
end if
For now when I try to use an non exisitng file name i am getting error, ***ERROR: Missing or invalid PHY
After searchng forums, i got to know that we can do error_handling using Eval(), but can some one explain how to use it in above scenario ?
Thanks
Leeladhar
3 REPLIES 3


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2010
08:45 PM
Re: How to check if a file exists in roku
To check for the existence of a local file, the roFileSystem component has an Exists() function.
If you want to check for the existence of a remote file, you could use the roURLTransfer component to perform a head request on the URL. Doing so for every poster item in your channel would probably cause performance issues though.
If you want to check for the existence of a remote file, you could use the roURLTransfer component to perform a head request on the URL. Doing so for every poster item in your channel would probably cause performance issues though.
leeladhar
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2010
12:56 AM
Re: How to check if a file exists in roku
Thanks RokuChris, that worked perfectly 🙂
Leeladhar
Leeladhar
leeladhar
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2010
03:41 AM
Re: How to check if a file exists in roku
This is the function I have written for this
Function fileExists(fileName As String) As Boolean
LocalFile = CreateObject("roRegex", "pkg:", "i")
LiveFile = CreateObject("roRegex", "http:", "i")
if(true = LocalFile.IsMatch(fileName))
LocalFileBrowser = CreateObject("roFileSystem")
return LocalFileBrowser.Exists(fileName)
else if(true = LiveFile.IsMatch(fileName))
print "fileName = "; fileName
LiveFileBrowser = CreateURLTransferObject(fileName)
LiveFileStatus = LiveFileBrowser.Head()
if( "200" = tostr(LiveFileStatus.GetResponseCode()) OR "304" = tostr(LiveFileStatus.GetResponseCode()))
return true
else
return false
end if
else
return false
end if
End Function