AutoHotkey Community

It is currently May 27th, 2012, 4:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: April 2nd, 2010, 9:25 am 
Offline

Joined: November 27th, 2006, 1:44 pm
Posts: 61
Location: Heerlen Country: Netherlands
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2010, 9:29 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Move your fileappends OUTside of the loops should help I suspect, build a variable with var .= new data "`n" and save only once using fileappend.

Also you loop the same structure twice? Can't you loop it once build a var with it and parse that variable rather than processing it all in the loop?

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2010, 9:43 am 
Offline

Joined: November 27th, 2006, 1:44 pm
Posts: 61
Location: Heerlen Country: Netherlands
that's not a problem, ut the problem is that the scanning itself takes a lot of time. (the inner most loops)
Code:
    Loop, \\nwafd\afd\Afdeling\%A_LoopFileName%\*.*,, 1
    {
        FolderSize += %A_LoopFileSize%
    }
These are the loops that take up the most of the time. writing to the file inside the loop is on purpose, because it sometimes happens that the virtual machine i have build for this script must reboot. i haven't added the logic jet to continue where it left off just before the reboot. this is meant for automatic dataprocessing of used space.
the excel files will be imported into another application witch will furter process the resulting files, but the scanning itself takes way to much time...

_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2010, 10:02 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Perhaps switching to an indexing tool (such as locate32) and read the results from that database would help. or create a tool that is continuously scanning in the background see 320mph adaptation by fures here http://www.autohotkey.com/forum/viewtop ... &start=300 which may provide some pointers.

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2010, 10:47 am 
Quote:
this is meant for automatic dataprocessing of used space


To get the total used space from a folder (and its subfolders) is a task that (when there are many files/folders to calculate) is better left to a 3p-tool, if you want it to be fast.

Try dirsize.exe (7k), it is the fastest utility that does this that I know of. Dunno if it works with network-addresses though.

Quote:
dirsize.exe -h
dirsize.exe [-switch] [dir]

switches:
-of fpath outputs to file fpath (not allowed with -oc)
-oc outputs to clipboard (not allowed with -of)
-fi formats output with ini-sections (not with -fd)
-fd outputs data only (same order as ini-sections, not with -fi))
-r scans directories recursive
-h prints this help (and nothing more)

dir directory to start scan from


HTH


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2010, 7:51 am 
Offline

Joined: November 27th, 2006, 1:44 pm
Posts: 61
Location: Heerlen Country: Netherlands
hugov wrote:
Perhaps switching to an indexing tool (such as locate32) and read the results from that database would help. or create a tool that is continuously scanning in the background see 320mph adaptation by fures here http://www.autohotkey.com/forum/viewtop ... &start=300 which may provide some pointers.
It's a good pointer and will look into how he does it's scanning.
n-l-i-d wrote:
Quote:
this is meant for automatic dataprocessing of used space


To get the total used space from a folder (and its subfolders) is a task that (when there are many files/folders to calculate) is better left to a 3p-tool, if you want it to be fast.

Try dirsize.exe (7k), it is the fastest utility that does this that I know of. Dunno if it works with network-addresses though.

Quote:
dirsize.exe -h
dirsize.exe [-switch] [dir]

switches:
-of fpath outputs to file fpath (not allowed with -oc)
-oc outputs to clipboard (not allowed with -of)
-fi formats output with ini-sections (not with -fd)
-fd outputs data only (same order as ini-sections, not with -fi))
-r scans directories recursive
-h prints this help (and nothing more)

dir directory to start scan from


HTH

Unfortunatly, does dirsize have it's limitations. It can't work with unc paths, but it does work (but only partially) if i first mount the unc patch to a drive and then execute dirsize. it can't however scan it's subdirectory's...

_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 77 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group