|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
I'm hoping there's a faster way to do this, since my current method takes an extremely long period of time. Basically what I'm wanting to do, is to generate a list of all the sound files (MP3, WAV, and MIDI) that are on my system. This is planned to be incorporated with a Sound Player (like an MP3 Player) dialog. I was using this code to try to get an idea as to how long it takes to find all of the files, but I've noticed that while running, my mIRC keeps showing up with a Not Responding message in the Titlebar, at which point all I can do is use Task Manager to end mIRC. menu * {
Sound : {
var %start = $ticks
var %a = $findfile(c:\,*.wav;*.mid;*.mp3,0)
;total time to locate all of the sound files
echo 4 -a %a found in $duration($calc(($ticks - %start) / 1000)) $calc(($ticks - %start) % 1000)
while %a {
;total time to locate each individual file
echo -a $findfile(c:\,*.wav;*.mid;*.mp3,%a,echo 12 -a $duration($calc(($ticks - %start) / 1000)) $calc(($ticks - %start) % 1000))
dec %a
}
}
}
I know that findfile is processor intensive, but I couldn't think of another way of doing this. P.S.: The Not Responding message shows up about 5 minutes after the code has started. Also, I think it should be noted that I have a count of 4669 found in 14secs 235 being reported in the first echo.
|
|
|
|
Joined: Sep 2003
Posts: 261
Fjord artisan
|
Fjord artisan
Joined: Sep 2003
Posts: 261 |
Well next time you do it and it stalls mirc just hold ctrl+break to exit the loop. Does not responding happen when you leave it alone? Or if you click on mirc while it's doing this?
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Leaving it alone. I know that $findfile is processor intensive, and that what I'm asking it to do is going to take a while, so I've purposely made it so that there's as little as possible operating at the same time.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
it isnt so much the findfile, its the number of times you run it, and even in a while loop? so if you find 500 total files, is that thing going to loop each one with a findfile? i tried this
alias finder {
set %findticks $ticks
noop $findfile(c:,*.wav;*.mp3;*.mid,0,findtick $ticks $nopath($1-))
}
alias findtick {
echo -s $calc($1 - %findticks) $2-
;echo -s $duration($calc(($1 - %findticks) / 1000)) $2-
}
and the first run it was slow enough to get a "not responding" message, but it did complete the task
|
|
|
|
Joined: Sep 2003
Posts: 261
Fjord artisan
|
Fjord artisan
Joined: Sep 2003
Posts: 261 |
Why not just use a .bat file and a windows command prompt command to pipe to a file? For instance, you can use the tree command already in windows to get you an entire list of every file on your computer in less than 10 seconds. Try this: run these from command prompt tree C: /a /f > filelist.txt find /N /I ".wav" C:\filelist.txt > filelistsearch.txt And just see where I'm going with this. Edited below: Heck this is even better . dir /S /B >c:\filelist4.txt
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
The best way that doesnt freeze mirc up is to use an external dos call to make a file to cover all matching files as shown, but if u do want to use findfile, then your method was flawed.
First you did a search that had to find every match, just to get you the total. Next you repeated a search looking for the Nth occrance, working N back from the max value to the minimal one. this essentially means for each loop u started a search from the first occurance and made findfile look for the Nth occrance, making it look over the same matches over and over and over.
The trick is to only go through the files once, gathering the results as you go Depending what you want here are three examples
//window -c @example | window -hl @example | echo -a Found $findfile(c:\,*.wav;*.mid;*.mp3,0,@example) Files in $calc( $ticks - [ $ticks ] ) ticks | window -w @example or //noop $findfile(c:\,*.wav;*.mid;*.mp3,0,echo -a $1-) or alias youraction.and.increment { echo -a $1 $2- | return $calc(1 + $1) } //var %i = 1 | echo -a ^ $findfile(c:\,*.wav;*.mid;*.mp3,0, var %i = $youraction.and.increment(%i,$1-)) files above
* i have used the last method myself often, it allows u to incrementally count the occrances, but does not requier the use of gobal vars
|
|
|
|
Joined: Sep 2003
Posts: 261
Fjord artisan
|
Fjord artisan
Joined: Sep 2003
Posts: 261 |
I just cooked this up see if you like it.
;type: /findfast C:\*.wav
alias findfast {
var %searchfor = $1-
var %findfasttxt = $+(", $scriptdirfindfast.txt, ")
var %findfastbat = $+(", $scriptdirfindfast.bat, ")
write -c %findfastbat dir %searchfor /S /B > %findfasttxt
if ($isfile(%findfastbat)) { run %findfastbat }
.timerresults 1 5 echo -a $lines(%findfasttxt)
}
This only took about 5 seconds on my system to find all the wav files I had and dumped there full path and all in 1 text file. You may want to adjust the timer to delay a bit longer depending on your processing.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
not cosistent line count echoed 0 336 464 153 207 153 153
very fast otherwise
|
|
|
|
Joined: Sep 2003
Posts: 261
Fjord artisan
|
Fjord artisan
Joined: Sep 2003
Posts: 261 |
Actually, it's consistant because it's a dos command built into windows ever since dos was created. It worked everytime for me, though I only have a small 40GB drive, the timer can sometimes report back before it's done making the complete file though. And any other system lag will contribute to how long it takes to completely search your drive. But the timer is only there for show for him right now. Increase the timer to 10 seconds after, and check out the file it creates. Notice, when you see the cmd prompt window show up, that's when it starts, and when it disappears that's when it stops, and has created the complete file. Here's a change of code:
;Usage: /findfast C:\*.wav
alias findfast {
var %searchfor = $1-
var %findfasttxt = $+(", $scriptdirfindfast.txt, ")
var %findfastbat = $+(", $scriptdirfindfast.bat, ")
write -c %findfastbat dir %searchfor /S /B > %findfasttxt
if ($isfile(%findfastbat)) { run %findfastbat }
.timerresults 1 10 echo -a $lines(%findfasttxt) $+ , File created: %findfasttxt
}
Returns for me 10 out of 10 times: 1397, File created: "C:\Program Files\mIRC\scripts\testzone\findfast.txt"
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Thanks for all of the replies, I think I'm going to go with something similar to DaveC's second example, as I don't need the information to be echoed, but stored in a hash table for future reference (this way I should only need to go through the process of finding the files once, and then reference them via the hash table entries afterwards).
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
I had a bit of a problem with this code of yours. When I ran it using /findfast c:\*.mp3 it returned 129 Yet using $findfile(c:\,*.mp3,0) returns 4201
I manually checked the My Music directory, and it alone has 729 mp3 files in it.
|
|
|
|
Joined: Sep 2003
Posts: 261
Fjord artisan
|
Fjord artisan
Joined: Sep 2003
Posts: 261 |
The timer! Here I'll explain again, The timer the first time echo'ed back the results in under 5 seconds, during that 5th second if the file was still building the list. Then yes it wouldn't of shown all of them, because it would still of been creating it. This bit of information I provided was only to show you the fastest speed. It is accurate if you give it enough time, and it's faster than mirc's $findfile will ever be. . Anyway good luck with your mission to find file the fastest way possible.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
ok...as you said, that was the problem, I had to try it a few times to get a timing that worked, and for that number of files, I actually had to go to 45 seconds before the numbers agreed...since I'm planning on including this as part of an MP3 Player dialog which will be posted for others to be able to use, and not knowing how many or what kind of files they're going to be working with, I need something that will return the correct number the first time and with a minimum delay. Again, thanks for the code, but I don't think I'll be incorporating it into the dialog.
|
|
|
|
Joined: Sep 2003
Posts: 261
Fjord artisan
|
Fjord artisan
Joined: Sep 2003
Posts: 261 |
k sorry I couldn't help then.
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
The fastest way is to use $findfile() with its internal looping feature, as MikeChat showed, but that may still cause freezing for a little while. If you're interested, WhileFix.dll is a dll that implements the same routines as $findfile(), but it won't freeze mIRC.
|
|
|
|
|