Jump to content

Faster solution - DIR output vs autoit internal..


MadBoy
 Share

Recommended Posts

Hello,

I've been using DIR output to find .inf files in subdirs of some dir. Recently i found on forum better (so i thought) method totally made in autoit so i thought it would be faster and nicer (less buggy). But it seems a looot slower. It's like 10seconds with DIR command output and over 1minute with with autoit only commands. So my question is anyone knows how to improve that autoit code to have it much faster? If it will be 10% slower i don't mind but when it's 600% slower it's preety much bad :P Lemme know :D

Func SearchDirectories($current)
     Local $extension = "inf"
     Local $search = FileFindFirstFile($current & "\*.*")
     Local $already_added = ""
     While 1
         Dim $file = FileFindNextFile($search)
         If @error Or StringLen($file) < 1 Then ExitLoop
         If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
 
             If StringRight($current & "\" & $file, StringLen($extension)) = $extension Then
                ;MsgBox (0, "Has the file extension " & $ext, $current & "\" & $file)
                ;this is where you do what you need to do
                 If $current <> $already_added Then
                     RegistryDevicePathMethod($current)
                 EndIf
                 $current = $already_added
             EndIf
         EndIf
         If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
             SearchDirectories($current & "\" & $file)
         EndIf
         Sleep(1)
     WEnd
     FileClose($search)
 EndFunc  ;==>SearchFiles
 
 Func RegistryDevicePathMethod($path_to_add)
     $registryadd = $path_to_add & ";"
     $oldkey = RegRead($HKLM & "\SOFTWARE\Microsoft\Windows\CurrentVersion", "DevicePath")
     $newkey = RegWrite($HKLM & "\SOFTWARE\Microsoft\Windows\CurrentVersion", "DevicePath", "REG_EXPAND_SZ", $oldkey & $path_to_add)
     If $logging_option = "Advanced" Then
         _AddLineBox("Added to registry: " & $path_to_add)
     EndIf
 EndFunc  ;==>RegistryDevicePathMethodoÝ÷ Ú÷«²ëºÚ"µÍY    ÌÍØÛÜWÙ]ÈH   ][ÝÖYÉ][ÝÈ[    ÌÍÙ]×Ù]HHÝ[ÓY
    ÌÍØÛÜWÝÚKJB  ÌÍÙ]×Ù]HHÝ[Õ ÌÍÙ]×Ù]JB[YY   ÌÍÛY]ÙH ][ÝÔYÚÝQ]XÙT]  ][ÝÈ[ÐY[PÞ
    ][ÝÔÙ][È][ÈYÚÝHÚ[ÈYÚÝQ]XÙT]Y]Ù][ÝÊBÈÙ]È]XÙT]ÈQUSY   ÌÍÜYÚÝWÜ]H    ][ÝÐYÚ[][ÝÈÜ  ÌÍÜYÚÝWÜ]H    ][ÝÉ][ÝÈ[YÕÜ]J    ÌÍÒÓH   [È ][ÝÉÌLÔÓÑÐTIÌLÓZXÜÜÛÙ  ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[Û][ÝË   ][ÝÑ]XÙT]    ][ÝË  ][ÝÔQ×ÑVSÔÖ][ÝË ][ÝÉTÞÝ[TÛÝ   IÌLÚ[É][ÝÊBY   ÌÍÜYÚÝWÜ]H    ][ÝÑ[ ][ÝÈÜ    ÌÍÜYÚÝWÜ]H    ][ÝÓÛI][ÝÈ[YÕÜ]J ÌÍÒÓH   [È ][ÝÉÌLÔÓÑÐTIÌLÓZXÜÜÛÙ  ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[Û][ÝË   ][ÝÑ]XÙT]    ][ÝË  ][ÝÔQ×ÑVSÔÖ][ÝË ][ÝÉ][ÝÊB   ÌÍÑÝ]]H[ÛÛTÜXÈ  [È ][ÝÈØÈTÐNÔÈ  ][ÝÈ  [È ÌÍÜ]Ý×Ù]Ë    ÌÎNÉÌÎNËÕ×ÒQKBÚ[HB    ÌÍÑ]HHÝÝ]XY
    ÌÍÑÝ]]
BYÜ[^]ÛÜY    ÌÍÑ]H[   ÌÍÑÝ]]ÛÙH [ÏH    ÌÍÑ]B[ÙBÛY
L
B[[È[[ÝHÜXÙÈÛHÝ]] ÌÍÑÝ]]ÛÙHHÝ[ÔÝÔÊ ÌÍÑÝ]]ÛÙKÊBÈÜ]Ý]][È^B    ÌÍÑÜ][ÔÜ]
    ÌÍÑÝ]]ÛÙKÔJBÜ   ÌÍÚHHHÈ ÌÍÑÜ]ÌBY   ÌÍÙXYÈH ][ÝÖYÉ][ÝÈ[ÐY[PÞ
    ][ÝÑPQÈ[QÒTÕQUPÑTUSÕSÓ  ][ÝÈ  [È ÌÍÑÜ]ÉÌÍÚWJBYÝ[Ò[Ý   ÌÍÑÜ]ÉÌÍÚWK ÌÍÜ]Ý×Ù]ÊH[Y ÌÍÙXYÈH ][ÝÖYÉ][ÝÈ[ÐY[PÞ
    ][ÝÑPQÈ[QÒTÕQUPÑTUSÕSÓN ][ÝÈ  [È ÌÍÑÜ]ÉÌÍÚWJB    ÌÍÜYÚÝÝ[ÈHÝ[ÔÜ]
    ÌÍÑÜ]ÉÌÍÚWK ÌÍÙ]×Ù]H   [È ][ÝÎÌLÉ][ÝËJBY    ÌÍÙXYÈH ][ÝÖYÉ][ÝÈS    ÌÍÜYÚÝÝ[ÖÌHHH[ÐY[PÞ
    ][ÝÑPQÈ[QÒTÕQUPÑTUSÕSÓ  ][ÝÈ  [È ÌÍÜYÚÝÝ[ÖÌH [È ][ÝÈH ][ÝÈ  [È ÌÍÜYÚÝÝ[ÖÌWJBY  ÌÍÙXYÈH ][ÝÖYÉ][ÝÈS    ÌÍÜYÚÝÝ[ÖÌHH[ÐY[PÞ
    ][ÝÑPQÈ[QÒTÕQUPÑTUSÕSÓ  ][ÝÈ  [È ÌÍÜYÚÝÝ[ÖÌH [È ][ÝÈH ][ÝÈ  [È ÌÍÜYÚÝÝ[ÖÌWH    [È ][ÝÈH ][ÝÈ  [È ÌÍÜYÚÝÝ[ÖÌJBY   ÌÍÜYÚÝÝ[ÖÌHH[ÈÝ[È[[Ý[Ù[[Y[È[^KY[ÜH[^]ÂYÝ[Ò[Ý ÌÍÙ]×Ù]H   [È ][ÝÎÌLÉ][ÝÈ   [È ÌÍÜYÚÝÝ[ÖÌK ÌÍÜ]Ý×Ù]ÊH[ÈXZÚ[ÈÝH]]È]^ÝÈ[Ý[ÂY ÌÍÙXYÈH ][ÝÖYÉ][ÝÈ[ÐY[PÞ
    ][ÝÑPQÈ[QÒTÕQUPÑTUSÕSÓΠ   ][ÝÈ  [È ÌÍÙ]×Ù]H   [È ][ÝÎÌLÉ][ÝÈ   [È ÌÍÜYÚÝÝ[ÖÌJBY   ÌÍÙXYÈH ][ÝÖYÉ][ÝÈ[ÐY[PÞ
    ][ÝÑPQÈ[QÒTÕQUPÑTUSÕSÓ
    ][ÝÈ  [È ÌÍÜYÚÝÝ[ÖÌJB    ÌÍÙ]×ÙXÝÜHH  ÌÍÙ]×Ù]H   [È ][ÝÎÌLÉ][ÝÈ   [È ÌÍÜYÚÝÝ[ÖÌB ÌÍÜÙXÚÚ[HH    ÌÍÙ]×ÙXÝÜH   [È ][ÝÉÌLÊ[][ÝÂY ÌÍÙXYÈH ][ÝÖYÉ][ÝÈ[ÐY[PÞ
    ][ÝÑPQÈ[QÒTÕQUPÑTUSÕSÓ
N   ][ÝÈ  [È ÌÍÜÙXÚÚ[JB    ÌÍÚÔÙXÚH[Q[Ý[J   ÌÍÜÙXÚÚ[JBY   ÌÍÚÔÙXÚ   ÉÝÈHH[Y  ÌÍÙXYÈH ][ÝÖYÉ][ÝÈ[ÐY[PÞ
    ][ÝÑPQÈ[QÒTÕQUPÑTUSÕSÓ
    ][ÝÈ  [È ÌÍÚÔÙXÚ
B   ÌÍÜYÚÝXYH  ÌÍÙ]×ÙXÝÜH   [È ][ÝÎÉ][ÝÂÐY[ÜÈ[ÈYÚÝB ÌÍÛÛÙ^HHYÔXY
    ÌÍÒÓH   [È ][ÝÉÌLÔÓÑÐTIÌLÓZXÜÜÛÙ  ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[Û][ÝË   ][ÝÑ]XÙT]    ][ÝÊB ÌÍÛ]ÚÙ^HHYÕÜ]J   ÌÍÒÓH   [È ][ÝÉÌLÔÓÑÐTIÌLÓZXÜÜÛÙ  ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[Û][ÝË   ][ÝÑ]XÙT]    ][ÝË  ][ÝÔQ×ÑVSÔÖ][ÝË ÌÍÛÛÙ^H    [È ÌÍÜYÚÝXY
BY  ÌÍÛÙÙÚ[×ÛÜ[ÛH ][ÝÐY[ÙY ][ÝÈ[ÐY[PÞ
    ][ÝÐYYÈYÚÝN    ][ÝÈ  [È ÌÍÙ]×ÙXÝÜJB[Y[Y[PÛÜÙJ ÌÍÚÔÙXÚ
B[Y[Y[Y^Y   ÌÍÜYÚÝWÜ]H    ][ÝÑ[ ][ÝÈ[ ÌÍÛÛÙ^HHYÔXY
    ÌÍÒÓH   [È ][ÝÉÌLÔÓÑÐTIÌLÓZXÜÜÛÙ  ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[Û][ÝË   ][ÝÑ]XÙT]    ][ÝÊB ÌÍÜYÚÝWÙ]×ÙY][H ][ÝÉTÞÝ[TÛÝ   IÌLÚ[É][Ý ÌÍÛ]ÚÙ^HHYÕÜ]J   ÌÍÒÓH   [È ][ÝÉÌLÔÓÑÐTIÌLÓZXÜÜÛÙ  ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[Û][ÝË   ][ÝÑ]XÙT]    ][ÝË  ][ÝÔQ×ÑVSÔÖ][ÝË ÌÍÛÛÙ^H    [È ÌÍÜYÚÝWÙ]×ÙY][
B[Y ÌÍÙ[[Ù^HHYÔXY
    ÌÍÒÓH   [È ][ÝÉÌLÔÓÑÐTIÌLÓZXÜÜÛÙ  ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[Û][ÝË   ][ÝÑ]XÙT]    ][ÝÊB ÌÍÙ[[Ù^WØÛÝ[[Ó[  ÌÍÙ[[Ù^JBÐY[PÞ
    ][ÝÑ]XÙH][YÚÝHÝ[HÈ   ][ÝÈ  [È ÌÍÙ[[Ù^WØÛÝ[ [È ][ÝËX^[][H]È
MÚXÝË][ÝÊBY    ÌÍÙ[[Ù^WØÛÝ[ ÝÈ
[ÐY[PÞ
    ][ÝÒ]ÈÝYÙÙÝY]Y]XÙH]ÈÛÙ[
ÚXÝÈ[ÝHÚÝ[ÙHÙ]ÛÜSÙ[R[Y]Ù][ÝÊBÐY[PÞ
    ][ÝÒY[ÝHÛÌÎNÝØ[ÈÈÛÈ[ÝHØ[Ý]ÛÛYH[YÈÛÈÜÙHÚ[HÚÜÝ][ÈÝÛH[XÙÚXÝÈÝ[][ÝÊB[Y  ÌÍÑ]XÙQ]ÈH ][ÝÔTÔÑQ    ][ÝÂÐY[PÞ
    ][ÝÑ]È]ØÈÙ]ÝXØÙÜÙ[H[ÈYÚÝK][ÝÊB[Y
Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

I can't see anything wrong with your code to make it take so long. I wrote a very similar routine to recursively check for files to backup and it is quite fast.

There are some very small changes to your code which might knock a few milliseconds off but I doubt this will give any noticeable improvement. However, maybe it's worth a try.

Func SearchDirectories($current)
     Local $search = FileFindFirstFile($current & "\*.*")
     Local $extension = "inf"
     Local $already_added = 0;<---------integer is faster than string
     While 1
         Dim $file = FileFindNextFile($search)
         If @error Or StringLen($file) < 1 Then ExitLoop
         if ($file <> "." And $file <> ".." Then;<-------extra loop for this condition
       If Not StringInStr(FileGetAttrib($current & "\" & $file), "D")Then
            If not $already_added then 
             If StringRight($file, StringLen($extension)) = $extension Then
                ;MsgBox (0, "Has the file extension " & $ext, $current & "\" & $file)
                ;this is where you do what you need to do
                  RegistryDevicePathMethod($current)
                  $already_added = 1
             EndIf
           EndIf

        Else;<---------------------instead of checking file attribs again
             SearchDirectories($current & "\" & $file)
         EndIf
     EndIf
     
         ;Sleep(1) - remove this if you want to go faster
     WEnd
     FileClose($search)
 EndFunc  ;==>SearchFiles
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Martin, calling the function from within itself like that with large filed folders could run into a recursive issue. The before mentioned _FileListToArrayEx that I wrote is much faster at the same time if speed is an issue.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Martin, calling the function from within itself like that with large filed folders could run into a recursive issue. The before mentioned _FileListToArrayEx that I wrote is much faster at the same time if speed is an issue.

Thanks SmOke N, that looks like a useful function. I might need that because I haven't worried about recursive problems. I've looked in the help and I see that the limit is currently 384 levels so I need to be aware of that.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Martin, calling the function from within itself like that with large filed folders could run into a recursive issue. The before mentioned _FileListToArrayEx that I wrote is much faster at the same time if speed is an issue.

Glad to see ya limit So can see....
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...