Jump to content

Recommended Posts

Posted

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)

  • Moderators
Posted

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)

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.

Posted

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

Posted

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)

Posted

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

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
  • Recently Browsing   0 members

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