LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best(Fast) way to search for a string in multiple files?

I have hundreds of files and would like to search for
barcode(text string). I tried ReadLine function but it
is too slow for mulriple files.
Any suggestions?
Any function for windows API I can use?
Thanks you in advance.
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 7
(3,897 Views)
I guess the other part of the question is... what do you plan to do once you
find the occurence. Do you plan to replace them by something else or
validate them or what...

Anyway, I would recomend :
for each txt file
load it in memory
use strstr function. Avoid any function from Format IO lib. They are
quite cool but too slow. Only use the ANSI C string function (in addition,
if you ever recompile you project with MSVC you will see great improvment in
term of speed while if you use Format IO lib there is no way to improve
speed since the project will be always using the code from the Formatio
lib).
If it is not enought, you could use the regular expression instrument
driver coming with CVI. In order to understand how it works...use it ! Heu,
how? Easy, l
oad one of your txt file in the C editor and make some test
(SHIFT +F3). Once you are satisfy with the expression to use then use the
instrument driver and re use the previous expression.
If the previous regular expression (the one from CVI) is not fast enough
use an other one (see http://arglist.com/regex/ for example)
Once you made the modification in the memory buffer, save the file back
on disk.

Note : Pay lot of attention to the fact that you will have to maintain
information about the size of the buffer each time you add/delete a char in
the buffer.

--
Philippe
Feel free to visit : http://perso.wanadoo.fr/philippe.baucour



"Sheetal" a écrit dans le message de news:
506500000008000000D7810000-1042324653000@exchange.ni.com...
> I have hundreds of files and would like to search for
> barcode(text string). I tried ReadLine function but it
> is too slow for mulriple files.
> Any suggestions?
> Any function for windows API I can use?
> Thanks you in advance.
0 Kudos
Message 2 of 7
(3,897 Views)
Thank you very much for your suggestions.
Once I find my string i need to read that line. I am not modifying the original file. Can I read whole file to array? (File size could be as big as 2 MB)
I am looking for something line this:

result=Check_String(*Filename, *string_to_search)
result=-1 if string not found
result>=0 string_to_search found where result is string_to_search position in file

Thanks.
Sheetal
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 3 of 7
(3,897 Views)
Yes you can load such a big file in memory. How much RAM do you have ? 256
Mo, 512 Mo... Believe me, there is enough room. In addition, since we are
all clean programmer we always check pointer value after a malloc and so we
cannot encounter any problem :-))

Yes you could load everything in an array but again, if you want it to go
fast you could do :
get file size
allocate the right amount of memory
load the file in one single shot in the allocated block
Do what you need to do on the strings
free memory

--
Regards, Philippe
Feel free to visit : http://perso.wanadoo.fr/philippe.baucour



"Sheetal" a écrit dans le message de news:
506500000005000000F4E50000-1042324653000@exchange.ni.com...
> Thank you very much for your suggestions.
> Onc
e I find my string i need to read that line. I am not modifying the
> original file. Can I read whole file to array? (File size could be as
> big as 2 MB)
> I am looking for something line this:
>
> result=Check_String(*Filename, *string_to_search)
> result=-1 if string not found
> result>=0 string_to_search found where result is string_to_search
> position in file
>
> Thanks.
> Sheetal
0 Kudos
Message 4 of 7
(3,897 Views)
thanks again for the reply.
I have 256 MB RAM.
I am doing following:
GetFileInfo (filename, &size);
malloc (size);
file = fopen (filename, "r");
fread (buffer, size, size, file);

Problem is how big my buffer should be. Looks like I am missing something.

Also, another question:
I want to use dos find command and would like to redirect output to a file. How do I do that?

I tried this but does not work.
system(find /N "Autodesk" c:\sample.txt >C:\sheetal.txt)

Any suggestions?
Thanks.
Sheetal
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 5 of 7
(3,897 Views)
You have to use Virtual Allocation for very big memory buffer. (Try to see inside the SDK.)
0 Kudos
Message 6 of 7
(3,897 Views)
My editor does this quite fast even though I don't know who it does it.

Why not take a look at grep code or if you have grep or equivalent on your
machine, just use it from CVI.

vishi

"Sheetal" wrote in message
news:506500000008000000D7810000-1042324653000@exchange.ni.com...
> I have hundreds of files and would like to search for
> barcode(text string). I tried ReadLine function but it
> is too slow for mulriple files.
> Any suggestions?
> Any function for windows API I can use?
> Thanks you in advance.
0 Kudos
Message 7 of 7
(3,897 Views)