i want to use a for loop to get video files from a list.
example file list:
video-1.mp4
video-2.mp4
video-3.mp4
video-4.mp4
this works to get the “number” of the videos i want.
videoNum=0
for i=1 to 4
videoNum = videoNum +1
print "video number is"; videoNum
end for
but this only returns the “Number”, so what do i need to do to add a number at the end of the video file?
i have tried adding a few different ways but i always get a type mismatch error.
arrays and loops confuse me so much at times, even in php… any help would be appreciated
I’m confused as to whether you have the names and know the format, and they are always something like “video-$NUMBER.mp4”, or whether you have a list of files, and just want to iterate through them.
For a known format, where the number is a monotonically increasing integer:
numFiles = 10
for i=0 to numFiles
filename = "video-"+i.toStr()+".mp4"
' do something
end for
For a list of files:
files = ["file1.mp4", "other.mp4", "file23534.mp4"]
for each file in files
' file contains filename from files array
' do something
end for
Or am I just completely missing your point?
filename = "video-"+i.toStr()+".mp4"
it was the toStr() i had left out. Thanks!
nope you hit it right on the head, will test it now…
im too busy playing ur new game 
“dynamitemedia” wrote:
filename = "video-"+i.toStr()+".mp4"
it was the toStr() i had left out. Thanks!
There’s also the stri() function, so you can do
filename = "video-"+stri(i)+".mp4"
but I prefer the interface methods.
im too busy playing ur new game 

now i have another question about this…
how could i do this with out knowing how many files there are? and want to get that number dynamically
numFiles = 10
say i want to check this folder for videos or images in this folder tmp:/new/
with image or video names like this:
image-01
image-02
or
video-01
video-02
i know in php i can do a count of files with that name, but how could i do that here? so it would then come back something like this:
filename = "image-"
whatever here to get the count of "filename" ending up with something like this
count =
numFiles = count
would it need the extension of the file? like .mp4 or .jpg ?
roFileSystem::Find() might be a simpler way to accomplish what you’re trying to do. The first parameter is the directory you want to search and the second is a regular expression that files must match to be included in the result, so to find all .mp4 or .jpg files in tmp:/new, you might say this…
fs = CreateObject("roFileSystem")
files = fs.Find("tmp:/new/", "\.(mp4|jpg)$")
thanks chris, i knew there had to be a function to do that.
i am not at home to check, but what if there are multiple .jpg’s but i only want the ones with the word
“newImage-” and these all have
01,02 etc on the end
could i use a " * " wildcard?
wildCard = "newImage-*.jpg"
fs = CreateObject("roFileSystem")
files = fs.Find("tmp:/new/", wildCard)
plus i will prob just need to use this for either a image or a video, but not together. but its awesome i know how to do it if i need to later!
“dynamitemedia” wrote:
could i use a " * " wildcard?
No, but you could use .*
Like this, assuming the files must BEGIN with newImage and end with .jpg.
wildCard = "^newImage-.*\.jpg$"
It uses a regular expression, not a shell expansion. That MUCH too large a topic to cover here. Luckily, there’s a plethora of tutorials to get you started online.
yes that is a whole another can of worms!!
and thanks, that actually makes sense what you added. Yes i wanted that name exactly, just in case other jpg’s or even mp4’s were still hanging around… didnt want the count wrong
most of these i will do server side, but its good to know what all options i have.
i’ll test when i get home if i have any more questions