milkshake333 Posted July 12, 2011 Share Posted July 12, 2011 Hi, I was wondering if it was possible to find a random file from a folder. As example, I have 50 .xml files in a folder, and they all have different names. Is there a function to get the contents of a folder, like files at a certain index, so I could just load a file when I have a number? Like 1-50? I hope you guys understand this... Regards, Rutger Speksnijder. Link to comment
#Paper Posted July 12, 2011 Share Posted July 12, 2011 (edited) So, import all files in the meta.xml, and then in the script: math.random(1, 50) and then u load xml file whit the random number Edited July 13, 2011 by Guest Link to comment
milkshake333 Posted July 12, 2011 Author Share Posted July 12, 2011 Yeah okay, but the problem is that if I have to import all the files in the meta.xml, it takes kinda long. 'Cause in this case, it's like 150 files. So I was wondering if there was some sort of function for this. Link to comment
#Paper Posted July 13, 2011 Share Posted July 13, 2011 Mhh, for open the files in the script i'm not sure that u need to insert these in the meta, u can try like: xmlLoadFile(":"..getResourceName(getThisResource()).."/"..math.random(1, 150)) But i'm not sure that works try... Link to comment
milkshake333 Posted July 13, 2011 Author Share Posted July 13, 2011 That doesn't work, because I said that the files all have a different name, and aren't just numbers. Link to comment
#Paper Posted July 13, 2011 Share Posted July 13, 2011 That doesn't work, because I said that the files all have a different name, and aren't just numbers. ah, in that can u have to add in meta Link to comment
milkshake333 Posted July 13, 2011 Author Share Posted July 13, 2011 Yeah okay, I already thought there was no function for this, though I didn't know for sure. Thanks for the help anyway . Link to comment
qaisjp Posted July 13, 2011 Share Posted July 13, 2011 Aha, are these xml's being generate by the same resource? In that case, when making an xml file, make a main xml file called master.xml, which specifies all the filenames of the generated ones. Then get the children, then use my function: function table.getr(t, min) return t[math.random(min or 1, table.getn(t))] end and then get the attributes and or value. But i cant guarantee itll work Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now