kneze Posted May 13, 2011 Share Posted May 13, 2011 Hi, how can i read content of txt file and get output in a window. My txt file has the folowing content: text;text1;text2;text3;text4;text5 the informations in my txt file are delimited with ; I would like to get the folowing output; Username=text LastLogon=text1 etc. thanks kneze Link to comment Share on other sites More sharing options...
wakillon Posted May 13, 2011 Share Posted May 13, 2011 Welcome to the forum ! try this ? #include <Array.au3> $_FilePath = 'c:\file.txt' $_Text = FileRead ( $_FilePath ) ConsoleWrite ( "$_Text : " & $_Text & @Crlf ) $_TextArray = StringSplit ( $_Text, ';' ) _ArrayDisplay ( $_TextArray ) MsgBox ( 4096, "", "username : " & $_TextArray[1] & @CRLF & _ "Lastlogon : " & $_TextArray[2] & @CRLF & _ "......... : " & $_TextArray[3] & @CRLF & _ "......... : " & $_TextArray[4] & @CRLF & _ "......... : " & $_TextArray[5] & @CRLF & _ "......... : " & $_TextArray[6] & @CRLF ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
kneze Posted May 13, 2011 Author Share Posted May 13, 2011 thanks. your code will work for me. only one question my txt file is on a network share. In the first step i would like to check if the file exist. The filename is "User id.txt" the complete Program 1. User Must enter Userid 2. IF Exist \\server\share\folder\%userid%.txt goto read file else message file does not exist. 3. read txt file content. the code that i have now is; #include <Array.au3> $sUserName = InputBox("UserID", "Enter User ID:") $_FilePath = 'sample.txt' $_Text = FileRead ( $_FilePath ) ConsoleWrite ( "$_Text : " & $_Text & @Crlf ) $_TextArray = StringSplit ( $_Text, ';' ) MsgBox ( 4096, "Last Userlogin INFO", "Lastlogon Date: " & $_TextArray[1] & @CRLF & _ "Domain: " & $_TextArray[2] & @CRLF & _ "CP Name: " & $_TextArray[3] & @CRLF & _ "User ID: " & $_TextArray[4] & @CRLF & _ "User: " & $_TextArray[5] & @CRLF & _ "Operating System:" & $_TextArray[6] & @CRLF & _ "Logon Server: " & $_TextArray[7] & @CRLF ) Link to comment Share on other sites More sharing options...
wakillon Posted May 13, 2011 Share Posted May 13, 2011 Something like this ? #include <Array.au3> $sUserName = InputBox("UserID", "Enter User ID:") $_FilePath = 'sample.txt' If Not FileExists ( '\\server\share\folder\' & $sUserName & '.txt' ) Then Exit MsgBox ( 0, 'Error', 'File does not Exists !', 5 ) $_Text = FileRead ( $_FilePath ) ConsoleWrite ( "$_Text : " & $_Text & @Crlf ) $_TextArray = StringSplit ( $_Text, ';' ) MsgBox ( 4096, "Last Userlogin INFO", "Lastlogon Date: " & $_TextArray[1] & @CRLF & _ "Domain: " & $_TextArray[2] & @CRLF & _ "CP Name: " & $_TextArray[3] & @CRLF & _ "User ID: " & $_TextArray[4] & @CRLF & _ "User: " & $_TextArray[5] & @CRLF & _ "Operating System:" & $_TextArray[6] & @CRLF & _ "Logon Server: " & $_TextArray[7] & @CRLF ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
kneze Posted May 13, 2011 Author Share Posted May 13, 2011 yes perfect. $sUserName = InputBox("UserID", "Enter User ID:") How can i Set FIle name to $_FilePath = $sUserName +.txt so if i enter user id: peter the file name would be peter.txt Link to comment Share on other sites More sharing options...
wakillon Posted May 13, 2011 Share Posted May 13, 2011 Like this $sUserName & '.txt' AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
kneze Posted May 13, 2011 Author Share Posted May 13, 2011 thanks a lot! works fine now =). Link to comment Share on other sites More sharing options...
kneze Posted May 15, 2011 Author Share Posted May 15, 2011 Hi the Script is a part in a "while" loop so if file not exist they will close script completly but i want to exit only this part of script. So i have While Case Button XXX If Not FileExists ( '\\server\share\folder\' & $sUserName & '.txt' ) Then Exit MsgBox ( 0, 'Error', 'File does not Exists !', 5 ) How can i do to return in while loop ? Link to comment Share on other sites More sharing options...
wakillon Posted May 15, 2011 Share Posted May 15, 2011 Suppress the Exit ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
kneze Posted May 15, 2011 Author Share Posted May 15, 2011 I have supress it 'exit' but the script go to next step wich only have to du if the file exist. Link to comment Share on other sites More sharing options...
smartee Posted May 15, 2011 Share Posted May 15, 2011 hi, Try replacing Exit with ContinueCase. -smartee Link to comment Share on other sites More sharing options...
wakillon Posted May 15, 2011 Share Posted May 15, 2011 I have supress it 'exit' but the script go to next step wich only have to du if the file exist.Show your loop script part. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
smartee Posted May 15, 2011 Share Posted May 15, 2011 Or, if you prefer, you can try something likeCase Button XXX If Not FileExists('\\server\share\folder\' & $sUserName & '.txt') Then MsgBox(0, 'Error', 'File does not Exists !', 5) Else ;Do your stuff EndIf Link to comment Share on other sites More sharing options...
kneze Posted May 15, 2011 Author Share Posted May 15, 2011 I Have a form with a lot of Buttons. in a while loop i have different "Cases". Here is a part of code Case $Button_batch22 i would like exit from $Button_batch22 if file doesn't exist and my Code is waiting for next button click. ;Check Size of userprofile (Remote Computer) Case $Button_batch22 ;save Variable $Input as $PCNamen $CPname = GuiCtrlRead($Input) If $CPname = "" Then MsgBox(0, "Error", "Missing Computer Nr. ") Else MsgBox(0, "Message", "User Profile Size will be calculated.") $var = Ping($CPname,250) If @error = 0 Then $sUserName = InputBox("UserID", "Enter UserID:") If Not FileExists ( "\\" & $cpname & "\c$\users\" & $sUserName ) Then MsgBox ( 0, 'Error', "No User Profile for " & $sUserName & "on "& $cpname & " found !", 5 ) MsgBox(0,"Userprofile Size", "CP Name: " & $CPname &@CRLF &@CRLF & "Userprofile Size for: " & $sUserName &@CRLF &@CRLF & Round(DirGetSize( "\\" & $cpname & "\c$\users\" & $sUserName)/1048576,2) & "MB") Else MsgBox(0, "Error", "Client not Online") EndIf EndIf Link to comment Share on other sites More sharing options...
wakillon Posted May 15, 2011 Share Posted May 15, 2011 Like this ? ;Check Size of userprofile (Remote Computer) Case $Button_batch22 ;save Variable $Input as $PCNamen $CPname = GuiCtrlRead($Input) If $CPname = "" Then MsgBox(0, "Error", "Missing Computer Nr. ") Else MsgBox(0, "Message", "User Profile Size will be calculated.") $var = Ping($CPname,250) If @error = 0 Then $sUserName = InputBox("UserID", "Enter UserID:") If Not FileExists ( "\\" & $cpname & "\c$\users\" & $sUserName ) Then MsgBox ( 0, 'Error', "No User Profile for " & $sUserName & "on "& $cpname & " found !", 5 ) Else MsgBox(0,"Userprofile Size", "CP Name: " & $CPname &@CRLF &@CRLF & "Userprofile Size for: " & $sUserName &@CRLF &@CRLF & Round(DirGetSize( "\\" & $cpname & "\c$\users\" & $sUserName)/1048576,2) & "MB") EndIf Else MsgBox(0, "Error", "Client not Online") EndIf EndIf AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
kneze Posted May 15, 2011 Author Share Posted May 15, 2011 Thanks. It works now. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now