Andromo - Start Making Apps - Free Signup

Announcement

Collapse
No announcement yet.

File.Find - How to find various types?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • File.Find - How to find various types?

    I want a table that contains the list of 3 types of files in a certain dir.

    How can I make a file.find function to find these 3 types (*.dbf, *.cdx and *.mem) and place then in a single table?

    Is there a way I can make one file.find to each type and then join the tables? How?
    Or there is a way that I can make a single file.find command to search the 3 types at once?

    Tanx !!

  • #2
    Here is some code that I made that finds three different file types and combines those files into one table. You can find this code in a project I did earlier. I believe it is called Advanced Listbox and Video control project, or something along those lines

    Code:
    	-- Find all avi files in the directory
    	aviFiles = File.Find(sDirectory, "*.avi", false, false, nil);
    	-- Find all mpg files in the directory
    	mpgFiles = File.Find(sDirectory, "*.mpg", false, false, nil);
    	-- Find all mpg files in the directory
    	wmvFiles = File.Find(sDirectory, "*.wmv", false, false, nil);
    	--create the tFiles table
    	tFiles = {};
    	
    	--if aviFiles contains something 
    	if aviFiles then
    		for aviIndex, aviFilePath in aviFiles do
    			--Add the files from aviFiles to tFiles table
    			Table.Insert(tFiles, Table.Count(tFiles) + 1, aviFilePath)
    		end
    	end		
    
    	--if mpgFiles contains something 
    	if mpgFiles then
    		for mpgIndex, mpgFilePath in mpgFiles do
    			--Add the files from mpgFiles to tFiles table
    			Table.Insert(tFiles, Table.Count(tFiles) + 1, mpgFilePath)
    		end
    	end
    	
    	--if wmvFiles contains something 
    	if wmvFiles then
    		for wmvIndex, wmvFilePath in wmvFiles do
    			--Add the files from wmvFiles to tFiles table
    			Table.Insert(tFiles, Table.Count(tFiles) + 1, wmvFilePath)
    		end
    	end
    To make it more compact you could have a table that contains all the extensions you want to find and then traverse that table to find all the file types. It would make the above code a lot smaller and more flexabile (for instance if you wanted to add another file type), ahh the power of tables.

    Code:
    tFileTypes = {"*.dbf", "*.cdx", "*.mem"};
    tFiles = {}
    for tin,tval in tFileTypes do
         foundfiles = File.Find(sDirectory, tval, false, false, nil);
         if foundfiles then
              for ffIndex, ffPath in foundfiles do
                   Table.Insert(tFiles, Table.Count(tFiles) + 1, ffPath)
              end
         end
    end
    tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

    Comment


    • #3
      WOW!!!

      I owe you a lot of tanx ... hehe...

      With this example code I could even understand what I couldnt before about some commands ... it helped a lot ... really....
      Tanx....

      I guess that with some more time I can have enough knowledge of the functions so I can have some creativity in creating the code and so I dont need to bother with stupid questions eheheheh

      Again, tanx!!!

      Comment

      Working...
      X