Sign in to follow this  
Followers 0
1badger11

Trying To Read Multiple File Size And Then Write To Log File

5 posts in this topic

Hello,

I am new to scripting and I have started playing with Autoit and I like it alot. I am trying to use the code below to read the file size of our user PST files and write them to a log file (either on the local machine or a central log file) that I can then either mail to myself or read in a central location. This is the main function I have come up with, but I do not have it quite right. Currently it reads the files and will display the file names, but it is not reading or writing the file size correctly (all zero file size). Any help, suggestions or improvements would be appreciated.

Thanks in advance,

Badger

#include "include\file.au3"

#include "include\mousefix.au3"

$Compname = @ComputerName

$Username = @UserName

$TMPDIR = EnvGet ( "TEMP")

$USERPROFILE = EnvGet ( "USERPROFILE")

$PATH = EnvGet ("PATH")

$LogFile = "c:\wkpstlog.txt"

$search = FileFindFirstFile(@UserProfileDir&"\local settings\application data\microsoft\outlook\*.pst")

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$Size = FileGetSize ($search)

;MsgBox(4096, "Size is:", $Size)

_FileWriteLog( $LogFile, "The current size for: " & $Username & " on " & $Compname & " is " & $Size)

$file = FileFindNextFile($search)

If @error Then ExitLoop

;MsgBox(4096, "File:", $file)

WEnd

; Close the search handle

FileClose($search)

Share this post


Link to post
Share on other sites



You can try this, with EnvGet/etc.. are you calling this from another script?

#include "include\file.au3"
#include "include\mousefix.au3"

$Compname = @ComputerName
$Username = @UserName
$TMPDIR = EnvGet ( "TEMP")
$USERPROFILE = EnvGet ( "USERPROFILE")
$PATH = EnvGet ("PATH")
$LogFile = "c:\wkpstlog.txt"

$search = FileFindFirstFile(@UserProfileDir&"\local settings\application data\microsoft\outlook\*.pst")

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    _FileWriteLog( $LogFile, "The current size for: " & $Username & " on " & $Compname & " is " & (FileGetSize($file) / 1048576) & ' mb(s)')
WEnd

FileClose($search)


[center]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.[/center]

Share this post


Link to post
Share on other sites

maybe

add ioncludes here


$Compname = @ComputerName
$Username = @UserName
$TMPDIR = EnvGet("TEMP")
$USERPROFILE = EnvGet("USERPROFILE")
$PATH = EnvGet("PATH")
$LogFile = "c:\wkpstlog.txt"


$search = FileFindFirstFile(@UserProfileDir & "\local settings\application data\microsoft\outlook\*.pst")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $Size = FileGetSize(@UserProfileDir & "\local settings\application data\microsoft\outlook\" & $file)
    
    MsgBox(4096, "File:", $file & @CRLF & $Size)
    
    _FileWriteLog($LogFile, "The current size for: " & $Username & " on " & $Compname & " is " & $Size)
    
WEnd

; Close the search handle
FileClose($search)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks to both of you, I combined elements from both to make it work correctly and more readable :think:

maybe

add ioncludes here
$Compname = @ComputerName
$Username = @UserName
$TMPDIR = EnvGet("TEMP")
$USERPROFILE = EnvGet("USERPROFILE")
$PATH = EnvGet("PATH")
$LogFile = "c:\wkpstlog.txt"
$search = FileFindFirstFile(@UserProfileDir & "\local settings\application data\microsoft\outlook\*.pst")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $Size = FileGetSize(@UserProfileDir & "\local settings\application data\microsoft\outlook\" & $file)
    
    MsgBox(4096, "File:", $file & @CRLF & $Size)
    
    _FileWriteLog($LogFile, "The current size for: " & $Username & " on " & $Compname & " is " & $Size)
    
WEnd

; Close the search handle
FileClose($search)

8)

Share this post


Link to post
Share on other sites

Welcome to the Forums

the only major difference i noted was the file get size... with location

$Size = FileGetSize(@UserProfileDir & "\local settings\application data\microsoft\outlook\" & $file)

8)


NEWHeader1.png

Share this post


Link to post
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
Sign in to follow this  
Followers 0