Your Digital Media Has Never Looked So Good

 
YungBlood
Topic Author
Posts: 133
Joined: Wed Jul 07, 2010 10:05 pm
Location: California
Contact:

Check if File Exists?

Wed Sep 01, 2010 1:37 am

Hi,
Is it possible to check to see if a file exists easily?

I would like to check to see if I've downloaded a file into tmp:/... and use it if it exists, rather than than just downloading it each time.
-Kevin
YungBlood

Bringing more fun to Roku!
 
renojim
** Valued Community Member **
Posts: 3491
Joined: Mon Feb 15, 2010 1:35 pm

Re: Check if File Exists?

Wed Sep 01, 2010 1:42 am

    x = MatchFiles("tmp:/",filename)
    if x.Count() = 0 then FILE DOES NOT EXIST


-JT
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9231
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: Check if File Exists?

Wed Sep 01, 2010 7:07 am

Or optionally...
fs = CreateObject( "roFileSystem" )
If fs.Exists( "tmp:/myfile") Then
    'found it
End If
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
 
YungBlood
Topic Author
Posts: 133
Joined: Wed Jul 07, 2010 10:05 pm
Location: California
Contact:

Re: Check if File Exists?

Wed Sep 01, 2010 12:48 pm

Thanks! :)
They both work. Though each one has it's advantages... I'm using the fs version since I don't want to parse the filename. :)

I'm starting to collect utility routines that roku is missing... I'll post them on my website later. Here's how I tried both styles

Function FileExists(file as String) as Integer
    last = 0
    l = len(file)
    for x = 1 to l
        r = instr(x, file, "/")
        if r > last then last = r
        if r = 0 then exit for
    end for   
    path = left(file, last)
    filename = right(file, l - last)
    return MatchFiles(path, filename).Count()
end function

Function FileExists(file as String) as Integer
    fs = CreateObject("roFileSystem")
    If fs.Exists(file) Then
        return 1
    End If
    return 0
end function
YungBlood

Bringing more fun to Roku!

Who is online

Users browsing this forum: No registered users and 5 guests