I use the below script to get a CSV file of 2 network drives with foldernames, the size of the folder and the date of the scan.
Is there any way to optimize this script so it runs any faster?
Currently the script runs for about 2 - 3 hours before it is complete.
Code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;SetBatchLines, -1
ScanAfdCSV = scan-afd.csv
ScanUsrCSV = scan-usr.csv
Costcenters = B:\dataverbruik_costcenters.xls
Gebruikers = B:\dataverbruik_gebruikers.xls
FileDelete, %ScanAfdCSV%
FileDelete, %ScanUsrCSV%
FileDelete, %Costcenters%
FileDelete, %Gebruikers%
ScanCount = 0
Voortgang = 0
Percent = 0
Loop,\\nwhome\home\*,2
{
Scancount += 1
}
Loop,\\nwafd\afd\*,2
{
Scancount += 1
}
Loop,\\nwafd\afd\Afdeling\*,2
{
Scancount += 1
}
Scancount -= 1
Progress, b w950 R0-%Scancount% Y0, Bezig met het controleren van het dataverbruik. PC niet gebruiken A.U.B., Dataverbruikscontrole, My Title
Logfile = %A_Temp%\dataverbruik.log
Progress, 0
FolderSize = 0
FileAppend, Ict/nwb-naam;Size;Datum`n, %A_ScriptDir%\%ScanAfdCSV%
Loop,\\nwafd\afd\Afdeling\*,2
{
Progress, %Voortgang%, Bezig met scannen van \\nwafd\afd\Afdeling\%A_LoopFileName% (%Percent%`%)
Loop, \\nwafd\afd\Afdeling\%A_LoopFileName%\*.*,, 1
{
FolderSize += %A_LoopFileSize%
}
FolderSize /= 1024
FolderSize /= 1024
FileAppend, Afdeling\%A_LoopFileName%;%FolderSize% MB;%A_DD%-%A_MM%-%A_YYYY%`n, %A_ScriptDir%\%ScanAfdCSV%
FolderSize =
Voortgang += 1
Percent := ( Voortgang / Scancount ) * 100
}
Loop,\\nwafd\afd\*,2
{
Progress, %Voortgang%, Bezig met scannen van \\nwafd\afd\%A_LoopFileName%
if A_LoopFileName = Afdeling
Continue
Loop, \\nwafd\afd\%A_LoopFileName%\*.*,, 1
{
FolderSize += %A_LoopFileSize%
}
FolderSize /= 1024
FolderSize /= 1024
FileAppend, %A_LoopFileName%;%FolderSize% MB;%A_DD%-%A_MM%-%A_YYYY%`n, %A_ScriptDir%\%ScanAfdCSV%
FolderSize =
Voortgang += 1
}
FolderSize = 0
FileAppend, Gebruikers;Size;Datum`n, %A_ScriptDir%\%ScanUsrCSV%
Loop,\\nwhome\home\*,2
{
Progress, %Voortgang%, Bezig met scannen van \\nwhome\home\%A_LoopFileName%
Loop, \\nwhome\home\%A_LoopFileName%\*.*,, 1
{
FolderSize += %A_LoopFileSize%
}
FolderSize /= 1024
FolderSize /= 1024
FileAppend, %A_LoopFileName%;%FolderSize% MB;%A_DD%-%A_MM%-%A_YYYY%`n, %A_ScriptDir%\%ScanUsrCSV%
FolderSize =
Voortgang += 1
}
Run, %ScanUsrCSV%
WinWait, Microsoft Excel - scan-usr, Horizontaal
IfWinNotActive, Microsoft Excel - scan-usr, Horizontaal, WinActivate, Microsoft Excel - scan-usr, Horizontaal
WinWaitActive, Microsoft Excel - scan-usr, Horizontaal
MouseClick, left, 276, 11
Sleep, 100
Send, {ALTDOWN}bl{ALTUP}
WinWait, Opslaan als, MSO Generic Control
IfWinNotActive, Opslaan als, MSO Generic Control , WinActivate, Opslaan als, MSO Generic Control
WinWaitActive, Opslaan als, MSO Generic Control
Send, %Gebruikers%{TAB}{DOWN}{UP 17}{DOWN 4}{ENTER 2}
WinWait, Microsoft Excel - dataverbruik_gebruikers, Horizontaal
IfWinNotActive, Microsoft Excel - dataverbruik_gebruikers, Horizontaal, WinActivate, Microsoft Excel - dataverbruik_gebruikers, Horizontaal
WinWaitActive, Microsoft Excel - dataverbruik_gebruikers, Horizontaal
Send, {ALTDOWN}{F4}{ALTUP}
Sleep, 1500
Run, %ScanAfdCSV%
WinWait, Microsoft Excel - scan-afd, Horizontaal
IfWinNotActive, Microsoft Excel - scan-afd, Horizontaal, WinActivate, Microsoft Excel - scan-afd, Horizontaal
WinWaitActive, Microsoft Excel - scan-afd, Horizontaal
MouseClick, left, 276, 11
Sleep, 100
Send, {ALTDOWN}bl{ALTUP}
WinWait, Opslaan als, MSO Generic Control
IfWinNotActive, Opslaan als, MSO Generic Control , WinActivate, Opslaan als, MSO Generic Control
WinWaitActive, Opslaan als, MSO Generic Control
Send, %Costcenters%{TAB}{DOWN}{UP 17}{DOWN 4}{ENTER 2}
WinWait, Microsoft Excel - dataverbruik_costcenters, Horizontaal
IfWinNotActive, Microsoft Excel - dataverbruik_costcenters, Horizontaal, WinActivate, Microsoft Excel - dataverbruik_costcenters, Horizontaal
WinWaitActive, Microsoft Excel - dataverbruik_costcenters, Horizontaal
Send, {ALTDOWN}{F4}{ALTUP}
_________________
Before asking a question try to read the
manual
Always use the code sections when you paste some code