Fastest way to loop through Folders

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Fastest way to loop through Folders

23 May 2019, 04:23

Hi, does anyone knows a faster way to loop through the folders / subfolders? I loop folders / subfolders in a local drive. There is about 4500 folders / subfolders. I gather each folder / subfolder path and write it in .txt file. To perform it using the method bellow, it takes 40 minutes. I think that should go faster...

Code: Select all

SetBatchLines, -1  ; affects CPU utilization... script will run at max speed
ListLines Off  ; helps with speed
Loop, Files, %TreeRoot%\*.*, DR
{
	FileAppend, %A_LoopFileFullPath%`n, %temp_Company_List%
}
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Fastest way to loop through Folders

23 May 2019, 04:46

Code: Select all

#NoEnv
SetBatchLines, -1  ; affects CPU utilization... script will run at max speed
ListLines Off  ; helps with speed

TreeRoot := "???"
temp_Company_List := "???"

ListFile := FileOpen(temp_Company_List, "w")
Loop, Files, %TreeRoot%\*.*, DR
{
   ListFile.Write(A_LoopFileFullPath . "`r`n")
}
ListFile.Close()
?
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: Fastest way to loop through Folders

23 May 2019, 06:14

It have reduced performance time from 40 min to 16 min. Pretty good, but maybe it's possible to make it even faster?
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Fastest way to loop through Folders

23 May 2019, 06:50

How long takes an 'empty' loop?

Code: Select all

#NoEnv
SetBatchLines, -1  ; affects CPU utilization... script will run at max speed
ListLines Off  ; helps with speed

TreeRoot := "???"
temp_Company_List := "???"

; ListFile := FileOpen(temp_Company_List, "w")
Loop, Files, %TreeRoot%\*.*, DR
{
   ; ListFile.Write(A_LoopFileFullPath . "`r`n")
   FilePath := A_LoopFileFullPath
}
; ListFile.Close()
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: Fastest way to loop through Folders

23 May 2019, 07:19

the same 16 minutes with the empty loop :/
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Fastest way to loop through Folders

23 May 2019, 07:41

That's weird! I don't have any further idea.
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: Fastest way to loop through Folders

23 May 2019, 07:46

each folder contains some files, maybe the loop scans those files too?
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Fastest way to loop through Folders

23 May 2019, 08:36

Perhaps look into https://autohotkey.com/board/topic/79420-ahk-l-listmftfiles-ntfs-instant-file-search/
Also check if your Antivirus doesn't interfere with AHK it might scan its actions and thus make it slow.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Fastest way to loop through Folders

23 May 2019, 10:13

One thing to note is that: doing one search can take a long time, but repeating that search immediately after, can be instant. I suppose because everything is cached.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Fastest way to loop through Folders

23 May 2019, 12:22

Code: Select all

Run, %ComSpec% /c dir /s /b /A:D> folders.txt,, Hide

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer and 252 guests