Jump to content

Multiple People running script [FileWrite]


Recommended Posts

hello all, and thanks to all for your help in advance. im going to be emailing this script to around 1200 users. it will copy a file to a created location. then save some info to a csv file on a network share. the below script works, im looking for best practice to code this script to not fail or hang when multiple users will write to the file at the same time.

#NoTrayIcon

Local $sDataFilePath = '\\servername\foldername\MasterFile.csv'
Local $sUserFolderPath = '\\servername\foldername\' & @UserName
Local $Input1 = $sUserFolderPath & '\Names.nsf'
Local $sTitle = 'Comany Name'

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIPassword.au3>

$Surreal = GUICreate($sTitle, 545, 230, -1, -1)
GUISetBkColor(0xFFFFFF)

$WhiteWavePic = GUICtrlCreatePic(@ScriptDir & '\image.jpg', 8, 55, 200, 121)

GUICtrlCreateLabel("Network Password:", 225, 130, 120, 17)
$InputPassword = _GUICtrlCreatePassword("", 225, 145, 300, 20)
$Checkbox = GUICtrlCreateCheckbox("Show password", 225, 170, 100, 17)

$Button = GUICtrlCreateButton("Submit", 370, 190, 120, 30)

GUICtrlCreateLabel("User Name:", 225, 40, 115, 17)
$InputUsername = GUICtrlCreateInput(@UserName, 225, 55, 300, 20)

GUICtrlCreateLabel("Email Address:", 225, 85, 115, 17)
$InputEmailAddress = GUICtrlCreateInput(@UserName & '@compantname.com', 225, 100, 300, 20)

GUICtrlCreateLabel("Transfer your Lotus Notes Contacts into Office 365", 95, 10, 345, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            $FormClose = MsgBox(36, $sTitle, "Are you sure you want to exit?")
            If $FormClose = 6 Then
                Exit
            EndIf
        Case $Button
            If GUICtrlRead($InputEmailAddress) = '' Or GUICtrlRead($InputPassword) = '' Then
                MsgBox(16, $sTitle, 'All fields must be entered.')
            Else
                _Export()
                GUIDelete($Surreal)
                MsgBox(64, $sTitle, "Done.")
                Exit
            EndIf
        Case $Checkbox
            _GUICtrlPasswordCheckbox($InputPassword, $Checkbox)
    EndSwitch
WEnd

Func _Export()
    DirCreate('\\servername\foldername\' & @UserName)
    FileCopy('C:\Program Files\Lotus\Notes\Data\names.nsf', '\\servername\foldername\' & @UserName & '\names.nsf', 1)

    FileWrite($sDataFilePath, $Input1 & "," & GUICtrlRead($InputEmailAddress) & "," & GUICtrlRead($InputPassword) & ",")

    FileWriteLine($sDataFilePath, "")
EndFunc   ;==>_Export

d@ve

Link to comment
Share on other sites

Might be best for each user to create their own file (named after their computer and user name), and have one process that collects those files, and adds them into the other.

No way to collide with that.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

example...have a dir that ALL files are created to, and the process loops through them, as they come in:

#include <file.au3>

DirCreate("YourFileOutputs")
; populate data, as an example
_FileCreate("YourFileOutputs\some1.txt")
FileWriteLine("YourFileOutputs\some1.txt","1,2,3,4,5")
FileWriteLine("YourFileOutputs\some1.txt","6,7,8,9,10")
_FileCreate("YourFileOutputs\some2.txt")
FileWriteLine("YourFileOutputs\some2.txt","1a,2a,3a,4a,5a")
FileWriteLine("YourFileOutputs\some2.txt","6a,7a,8a,9a,10a")

; actual code you will use
_FileCreate("combined.txt")

While True
    $a = _FileListToArray("YourFileOutputs")
    For $i = 1 To UBound($a)-1
        Local $aTemp = ""
        Sleep(250) ; make sure the file is fully populated...add more time if your process is slow
        _FileReadToArray("YourFileOutputs\" & $a[$i],$aTemp)
        For $j = 1 To UBound($aTemp)-1
            FileWriteLine("combined.txt",$aTemp[$j])
        Next
        FileDelete("YourFileOutputs\" & $a[$i])
    Next
    Sleep(5000)
WEnd
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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
 Share

  • Recently Browsing   0 members

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