Jump to content



Recommended Posts

This is the complete code i have workin, it's pretty messy perhaps someone could help me make it more simple than this i will appreciate it :o

#include <date.au3>
#include <file.au3>

$iniRpath = "S:\OTSYS\autoUp\"  
$srcdir = "S:\OTSYS\update\"            
$destdir = "C:\OTSYS\"      
$bakdir = "C:\OTSYS\backup\"
$srcsize = DirGetSize($srcdir)                                          
$lastsize = iniRead("c:\otsys.ini","source","sizeLast","0")             
$curRver = iniRead($iniRpath & "otsys.ini","source","version","err")
$curVer = iniread("C:\otsys.ini","destination","version","err")

if $curRVer = "err" or $curVer = "err" then
    msgbox(0,"Update Failure", "OTSYS update system is malfunction, please contact elkie.")
    _FileWriteLog($iniRpath & "report.log", @ComputerName & "(" & @UserName & ")" & " Failed," & " version " & $curRver)
if $curRver > $curVer then
    if $srcsize <> $lastsize then                       
    ;contributed from autoIT forum member by  Nuffilein805
        $files = filefindfirstfile($srcdir & "*.*")
        while 1
            $file = filefindnextfile($files)
            if @error Then exitloop
            if $file = "." or $file = ".." Then
            if fileexists ($destdir & $file) then FileCopy ($destdir & $file, $bakdir & "*", 8)
        $resC=filecopy ($srcdir & "*", $destdir & "*", 9)
        if $resC = 1 then                                               
            TrayTip("OTSYS","Update Successfull",5,1)
            TrayTip("OTSYS","Files already UpToDate",3,1)
    _FileWriteLog($iniRpath & "report.log", @ComputerName & "(" & @UserName & ")" & " Updated," & " version " & $curRver)
    TrayTip("OTSYS","Files already UpToDate",3,1)
Link to comment
Share on other sites

Oh btw i just realize that u put 8 and 9 for the filecopy() flag, i didn't found any description about those value in the AutoIT Help file, there's only 2 flag for the function (0 and 1), what are those number means and please update about it to the help file

Link to comment
Share on other sites

  • Moderators

well usually i don't care but as i said i'm tired --- have fun with this script and tell me if it works as you wanted it

maybe you want to post your complete finished code so we can have a look at it :o


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.

Link to comment
Share on other sites

there is a mistakes in your script

$curRver = iniRead($iniRpath & "otsys.ini","source","version","err")
$curVer = iniread("C:\otsys.ini","destination","version","err")
if $curRver > $curVer then
should be replaced by

$curRver = iniRead($iniRpath & "otsys.ini","source","version","err")
$curVer = iniread("C:\otsys.ini","destination","version","err")
if ... = "err"
$curRver = number($curRver)
$crVer = number($curVer)
;because 9 > 10 !!! if you change it to number it should work if you don't have versions like 3.1.999 - maybe you should stringsplit those
if $curRver > $curVer then

thats all by now - i hope

have fun

Link to comment
Share on other sites

I don't know what time of day, how many workstations, how many files to test for revision, and etc...I wanted to offer my $0.02 and recommend developing a script using the DOS Xcopy Command. This is an extremely powerfull command I use to backup servers and copy patches/updates to workstations. It might be right for you. Here is the reference...

Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]

  source        Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A               Copies only files with the archive attribute set,
                    doesn't change the attribute.
  /M               Copies only files with the archive attribute set,
                     turns off the archive attribute.
  /D:m-d-y   Copies files changed on or after the specified date.
                     If no date is given, copies only those files whose
                     source time is newer than the destination time.
  /EXCLUDE:   file1[+file2][+file3]...
                     Specifies a list of files containing strings.  Each string
                     should be in a separate line in the files.  When any of the
                     strings match any part of the absolute path of the file to be
                     copied, that file will be excluded from being copied.  For
                     example, specifying a string like \obj\ or .obj will exclude
                     all files underneath the directory obj or all files with the
                     .obj extension respectively.
  /P                Prompts you before creating each destination file.
  /S                Copies directories and subdirectories except empty ones.
  /E                Copies directories and subdirectories, including empty ones.
                     Same as /S /E. May be used to modify /T.
  /V                Verifies each new file.
  /W               Prompts you to press a key before copying.
  /C               Continues copying even if errors occur.
  /I                If destination does not exist and copying more than one file,
                     assumes that destination must be a directory.
  /Q               Does not display file names while copying.
  /F                Displays full source and destination file names while copying.
  /L                Displays files that would be copied.
  /G               Allows the copying of encrypted files to destination that does
                     not support encryption.
  /H               Copies hidden and system files also.
  /R               Overwrites read-only files.
  /T               Creates directory structure, but does not copy files. Does not
                     include empty directories or subdirectories. /T /E includes
                     empty directories and subdirectories.
  /U               Copies only files that already exist in destination.
  /K               Copies attributes. Normal Xcopy will reset read-only attributes.
  /N               Copies using the generated short names.
  /O               Copies file ownership and ACL information.
  /X               Copies file audit settings (implies /O).
  /Y               Suppresses prompting to confirm you want to overwrite an
                    existing destination file.
  /-Y             Causes prompting to confirm you want to overwrite an
                    existing destination file.
  /Z               Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.
Link to comment
Share on other sites

If your enviroment is XP and/or 2003, even better than xcopy is robocopy.exe (Robust Copy) provided in the Windows 2003 Resource Kit. Is great for network file managment and even has the ability to 'listen' for changes in a directory or on a file(s). I found the included robocopy.doc to pretty thorough. Read the doc well before tackling writing scripts for it though. There are so many options that sometimes it gets confusing when using one in partcular does not work while using another and logic says it should and doc's don't say if it does or doesn't. (Grammar check anyone? :o )

Windows 2003 Resource Kit download

Google 'robocopy'

Link to comment
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

  • Recently Browsing   0 members

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