Andy2k14 Posted May 29, 2014 Posted May 29, 2014 Hi all, Still learning AutoIt, can anyone recommend how i can do the following: Continuously search for a .txt file in a designated directory The search will continue indefinatley until the user closes the program or the file is found If file found open file and read 1st line of txt file close file end program Ive been looking at using the "read first line" function but having difficulty with the syntax format. The example is not (in my opinion) noob friendly. Any help appreciated
Moderators Melba23 Posted May 29, 2014 Moderators Posted May 29, 2014 Andy2k14, Ive been looking at using the "read first line" functionAre you speaking about FileReadLine? If so, then the default is to read the first line, so a simple:FileReadLine("filename")will do what you want. As to detecting the file in the first place, I suggest FileExists in an infinite loop with a suitable Sleep to prevent the CPU overheating - ExitLoop will get you out of the loop once the file has been found and read. See how you get on with that and come back if you run into problems. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
November Posted May 29, 2014 Posted May 29, 2014 (edited) Hi Andy2k14 I'm in a great mood today so here is some of my code but use it to learn and modify it as you wish. Dim $file, $match, $openfile, $readline ;declaration $file = "c:\temp\file.txt"; file path and name While 1 $match = FileFindFirstFile($file);check if file exists if $match = -1 Then exiterror();ops... is not there $openfile = FileOpen($file, 0) ; opening in read mode If $openfile = -1 Then MsgBox(16, "Error", "Error opening file");what is happening with this file... i'll have to check it! $readline = FileReadLine($file, 1) ; read 1st line Select Case @error = 1;check help in autoit MsgBox(16, "Error", "File not open in read mode");File read failed due open file Case @error = -1;check help in autoit MsgBox(48, "Error", "File is empty");File read failed due no data in file EndSelect exitnoerror();everything went well let's exit with sucess sleep (50) WEnd Func exiterror() MsgBox(16, "Search File", "file " & $file & " not found"); file not found, here you can choose to continue loop or not Exit;exiting script EndFunc ;==>exiterror Func exitnoerror() MsgBox(64, "Search File", "file " & $file & " found" & @CRLF & "Text : " & $readline) ; text of the 1st line here Exit EndFunc ;==>exitnoerror Cheers Edited May 29, 2014 by November Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font]
Danyfirex Posted May 29, 2014 Posted May 29, 2014 you simply could do something like this: Global $fExit= False HotKeySet("{ESC}", "_Exit") Local $sFileData="" Do Sleep(30) FileReadLine("File.exe",1) Until Not @error or $fExit Func _Exit() $fExit=True EndFunc Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
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