PDA

View Full Version : How do I search for two files or more



aliali
12-24-2009, 09:35 PM
welcome

How do I search for two files or more
In this example:

Oggs = File.Find( _SourceFolder, "*.ogg", true, false, ShowSearchProgress, nil);



Thanks

jassing
12-24-2009, 11:44 PM
How do I search for two files or more
In this example:

Oggs = File.Find( _SourceFolder, "*.ogg", true, false, ShowSearchProgress, nil);



Just like that -- it will find multiple files that match your filemask "*.ogg"

aliali
12-25-2009, 09:04 AM
Thank you for attention
Sorry
I mean the search for more than type
Example:. Ogg,. Wav and so on
Thank you

T3STY
12-25-2009, 09:18 AM
aliali, would you please write without aligning to center the text ? Thankyou.



I mean the search for more than type

just add a coma after previous extension the add the new extension.
i.e:


Oggs = File.Find( _SourceFolder, "*.ogg, *.mp3, *.wav, *.wma", true, false, ShowSearchProgress, nil);


Bye!

EDIT
Hmmm.. sorry I'm not even sure this is the right code... I hope it is..

aliali
12-25-2009, 10:07 AM
hi
But the problem is not solved
example facility
thank you very much

Tomasin
12-25-2009, 10:17 AM
hi

search for multiple file extension not is possible with AMS.

azmanar
12-25-2009, 10:21 AM
Hi Ali,

There are several examples you can find here : http://www.indigorose.com/forums/forumdisplay.php?f=56

Try downloading the samples and checking them out.

aliali
12-25-2009, 10:35 AM
I have seen several examples where, but not what I'm looking
All thanks and appreciation

T3STY
12-25-2009, 10:50 AM
Here is an example that uses a table with file formats to check:


--Get wich disk is selected in the ComboBox object
nSelected = ComboBox.GetSelected("ComboBox1");
if not (nSelected == -1) then
sDrive = ComboBox.GetItemData("ComboBox1", nSelected);
end

--Create a table with the file formats to check
tblFileFormats = {};
tblFileFormats.ogg = "*.ogg";
tblFileFormats.mp3 = "*.mp3";
tblFileFormats.wav = "*.wav";
tblFileFormats.wma = "*.wma";

--Check to see if sDrive is not an empty variable because of some errors occured before
if not (sDrive == "") then
--Clear the ListBox
ListBox.DeleteItem("ListBox1", -1);

--Search for files
--for each table index (sFileFormat) in the file formats table (tblFileFormats) do..
for sFileFormat in tblFileFormats do

--Search for files with the extension from the table
sFilePath = File.Find(sDrive, sFileFormat, true, true, nil, nil);

--if there didn't occured any error
if (sFilePath) then

--split the path and assign some variables
tblSplittedPath = String.SplitPath(sFilePath);
sFile = tblSplittedPath.Filename;
sExtension = tblSplittedPath.Extension;

--Add an item to ListBox
ListBox.AddItem("ListBox1", sFile..sExtension, sFilePath);
end
end
end


The problem for this is that it checks as much times as the number of indexes in the table of formats, so it may be slow. Later I'll post some other code wich will be better.

Bye!

p.s. You can copy and paste this code on the OnClick event of your button in you application, the code is built based on your example posted before.

T3STY
12-25-2009, 11:09 AM
OK, here it is the new code:



--Get wich disk is selected in the ComboBox object
nSelected = ComboBox.GetSelected("ComboBox1");
if not (nSelected == -1) then
sDrive = ComboBox.GetItemData("ComboBox1", nSelected);
end

--Create a table with the file formats
tblFileFormats = {};
tblFileFormats.ogg = ".ogg";
tblFileFormats.mp3 = ".mp3";
tblFileFormats.wav = ".wav";
tblFileFormats.wma = ".wma";

--[[Check to see if sDrive is not an empty variable because of some errors occured before
if this will cause some errors, replace the line

if not (sDrive == "") then

with

if not (sDrive == "") and not (sDrive == nil) then
]]--

if not (sDrive == "") then
--Clear the ListBox
ListBox.DeleteItem("ListBox1", -1);

--Search for files
tblFiles = File.Find(sDrive, "*.*", true, true, nil, nil);

--for each file in tblFiles do..
for sFilePath in tblFiles do

--Splith path..
tblSplittedPath = String.SplitPath(sFilePath);

--and set a variable for file's extension
sExtension = tblSplittedPath.Extension;

--for each extension in the table, check to see if it's as same as the result
for sFileFormat in tbFileFormats do

--if the extension of the file is as same as the one from the table..
if (sFileFormat == sExtension) then

--set a variable for the file name without extension
sFile = tblSplittedPath.Filename;

--add an item to the ListBox
ListBox.AddItem("ListBox1", sFile..sExtension, sFilePath);
end
end
end
end


Hope this can help you :)
Bye!

aliali
12-25-2009, 11:53 AM
Thank you very much for your concern and assistance
However, there is an error and this image
http://img163.imageshack.us/img163/3817/61843157.jpg
Sincere greetings

Sakuya
12-25-2009, 01:52 PM
Just run File.Find and then when looping through do an if statement like this.


for K, V in pairs(Results) do
local ext = String.SplitPath(V).Extension;

if (ext == ".ogg" or ext == ".wma") then
-- stuff
end
end

aliali
12-25-2009, 03:27 PM
Wonderful

But there is also an error message

http://img268.imageshack.us/img268/4923/001urv.jpg

Thank you all for attention and assistance

Scriptonite
12-25-2009, 05:48 PM
Try this:


folder = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\Docs");


if folder ~= "CANCEL" then

tbFiles = {"*.ogg", "*.wma"};

for i,type in tbFiles do
file = File.Find(folder, type, false, false, nil);
if file ~= nil then
for j,path in file do
--Your Actions Here
Dialog.Message("Found File",path)

end
end
end

end



This was based on an example from somewhere, i'm not sure where it is from though. Probably one of the examples from the link that was posted by azmanar.

aliali
12-25-2009, 06:45 PM
Thank you for attention and assistance
But I awaited follow-up to Mr:T3STY
works on the same example that was sent
Or any teacher working on the same example, which was sent
I apologize to double in the English language

With my sincere greetings

T3STY
12-26-2009, 04:53 AM
Wich code did you try wich give's you the error before ?

anyhow, both examples are made based on your test example, you can copy the code on OnClick event of your button.

I attached here the example with the last code i made and it seems to work for me.

p.s. to close it before the search ends, you must use the task manager 'cause it has no callback function to stop the search.

aliali
12-27-2009, 05:00 PM
T3STY

Thank you very much
Sincere greetings

jotasgk
09-30-2010, 03:49 PM
--Clear the ListBox
ListBox.DeleteItem("ListBox1", -1);

--Search for files
tblFiles = File.Find(sDrive, "*.*", true, true, nil, nil);

--for each file in tblFiles do..
for sFilePath in tblFiles do

--Splith path..
tblSplittedPath = String.SplitPath(sFilePath);

--and set a variable for file's extension
sExtension = String.Lower(tblSplittedPath.Extension);

--for each extension in the table, check to see if it's as same as the result
for sFileFormat in tbFileFormats do

--if the extension of the file is as same as the one from the table..
if (sFileFormat == sExtension) then

--set a variable for the file name without extension
sFile = tblSplittedPath.Filename;

--add an item to the ListBox
ListBox.AddItem("ListBox1", sFile..sExtension, sFilePath);
end
end
end
end