KennethF Posted April 15, 2011 Posted April 15, 2011 Hi there.. - I´am totally new to this AutoIT software.. I hope someone can help me with this little task.. I need a program that can check if a file exists and if so - then execute a external program with some parameters.. Basically this is what the program should do: 1. Check directory c:\ftp\location1\ for a file named 1.txt 2. If the file exist then execute this program c:\ftp\program\start.exe root:test@192.168.1.100/start and rename the file 1.txt to 2.txt Next 3. Check directory c:\ftp\localtion2\ for a file named 1.txt 4. If the file exist then execute this program c:\ftp\program\start.exe root:test@192.168.1.101/start and remame the file 1.txt to 2.txt Continue this way for about 15 directories And then 5. Check directory c:\ftp\localtion1\ if there is 3 JPG files in here - then rename the file 2.txt to 3.txt 6. Check directory c:\ftp\localtion2\ if there is 1 JPG file in here - then rename the file 2.exe to 3.txt Continue for all the directories.. about 15. and then finally start all over in a loop monitoring these directories.. I tried doing something like this - but cant figure out how to do the rest.. ************************ If FileExists("c:\ftp\location1\1.txt") Then Run ("notepad.exe") If FileExists("c:\ftp\location2\1.txt" Then run ("notepad.exe") EndIf PS. Just using notepad.exe instead of the start.exe file to see the result.. Hope that someone can help me.. :-) Best regards, Kenneth
wakillon Posted April 15, 2011 Posted April 15, 2011 (edited) welcome to the forum ! you could start like this : For $_I = 1 To 15 $_FilePath = "c:\ftp\location" & $_I & "\1.txt" ConsoleWrite ( $_I & " $_FilePath : " & $_FilePath & @Crlf ) If FileExists ( $_FilePath ) Then RunWait ( 'c:\ftp\program\start.exe root:test@192.168.1.10' & $_I -1 & '/start' ) $_Renamed = "c:\ftp\location" & $_I & "\" & $_I +1 & ".txt" ConsoleWrite ( " $_Renamed : " & $_Renamed & @Crlf ) FileMove ( $_FilePath, $_Renamed ) EndIf Next Do you want to check for jpeg in this loop or after ? And if Check directory c:\ftp\localtion15, how many jpg do you want find... 5. Check directory c:\ftp\localtion1\ if there is 3 JPG files in here - then rename the file 2.txt to 3.txt 6. Check directory c:\ftp\localtion2\ if there is 1 JPG file in here - then rename the file 2.exe to 3.txt Continue for all the directories.. about 15. Edited April 15, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
KennethF Posted April 15, 2011 Author Posted April 15, 2011 Hey it worked.. - great..!!! - however I´am having alot of thinking - how does it work with all that scripting.. What if I want to make it more sort of a line by line programming without all those variables.. more beginners programming.. - and if the location1 instead is the name of a city and then another cityname.. Really looking forward to hearing from you.. :-) Best regards, Kenneth.. :-)
wakillon Posted April 15, 2011 Posted April 15, 2011 (edited) like this ?Global $_CityArray[16]=["Paris", "London", "Madrid", "Rome", "Moscow", "New York", "Tokyo", "Sydney", "Berlin", "Bruxelles", "Rio", "Panama", "Washington", "Riga", "Prague"] For $_I = 1 To UBound ( $_CityArray ) -1 $_FilePath = "c:\ftp\" & $_CityArray[$_I] & "\1.txt" ConsoleWrite ( $_I & " $_FilePath : " & $_FilePath & @Crlf ) If FileExists ( $_FilePath ) Then RunWait ( 'c:\ftp\program\start.exe root:test@192.168.1.10' & $_I -1 & '/start' ) $_Renamed = "c:\ftp\" & $_CityArray[$_I] & "\" & $_I +1 & ".txt" ConsoleWrite ( " $_Renamed : " & $_Renamed & @Crlf ) FileMove ( $_FilePath, $_Renamed ) EndIf NextI put variables for display them in console, for a better understanding ! Edited April 15, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
KennethF Posted April 15, 2011 Author Posted April 15, 2011 Yes ! - this is just great.. Then I just need it to detect # of JPGs - usally 1-3 jpgs per cityname and if they are there rename 2.txt to 3.txt And just loop the entire program Can you fix that also.. ?.. :-) Best regards, Kenneth
KennethF Posted April 15, 2011 Author Posted April 15, 2011 Btw. - I was just looking at your script.. - It needs to call the start.exe with different IP for each city.. Example: Check city "london" for 1.txt IF exist then call start.exe 192.168.1.10/parameter Checi city "Moscow" for 1.txt IF exist then call start.exe 192.168.42.5/parameter Hope you are still willing to help me.. Best regards, Kenneth
wakillon Posted April 15, 2011 Posted April 15, 2011 Like this ? #Include <File.au3> Global $_CityArray[16]=["Paris", "London", "Madrid", "Rome", "Moscow", "New York", "Tokyo", "Sydney", "Berlin", "Bruxelles", "Rio", "Panama", "Washington", "Riga", "Prague"] While 1 For $_I = 1 To UBound ( $_CityArray ) -1 $_FilePath = "c:\ftp\" & $_CityArray[$_I] & "\1.txt" ConsoleWrite ( $_I & " $_FilePath : " & $_FilePath & @Crlf ) If FileExists ( $_FilePath ) Then RunWait ( 'c:\ftp\program\start.exe root:test@192.168.1.10' & $_I -1 & '/start' ) $_Renamed = "c:\ftp\" & $_CityArray[$_I] & "\" & $_I +1 & ".txt" ConsoleWrite ( " $_Renamed : " & $_Renamed & @Crlf ) FileMove ( $_FilePath, $_Renamed ) EndIf Next For $_I = 1 To UBound ( $_CityArray ) -1 $_SearchPath = "c:\ftp\" & $_CityArray[$_I] ConsoleWrite ( " $_SearchPath : " & $_SearchPath & @Crlf ) Switch _CheckForJpegNumber ( $_SearchPath ) Case 1, 2, 3 FileMove ( $_SearchPath & '\2.txt', $_SearchPath & '\3.txt' ) Case Else ; EndSwitch Next WEnd Func _CheckForJpegNumber ( $_FolderPath ) $FileList = _FileListToArray ( $_FolderPath, '*.jpg' ) If @Error Then Return 0 $_NumberOfJpeg = UBound ( $FileList ) -1 Return $_NumberOfJpeg EndFunc AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
wakillon Posted April 15, 2011 Posted April 15, 2011 I don't see your last , so...And like this ? expandcollapse popup#Include <File.au3> Global $_CityArray[16][2]=[ ["Paris", "192.168.0.1/parameter"], ["London", "192.168.1.10/parameter"], ["Madrid", "192.168.22.3/parameter"], _ ["Rome", "192.168.52.9/parameter"], ["Moscow", "192.168.42.5/parameter"], ["New York", "192.168.66.0/parameter"], _ ["Tokyo", "192.168.72.1/parameter"], ["Sydney", "192.168.33.2/parameter"], ["Berlin", "192.168.38.6/parameter"], _ ["Bruxelles", "192.168.8.1/parameter"], ["Rio", "192.168.1.1/parameter"], ["Panama", "192.168.00.5/parameter"], _ ["Washington", "192.168.92.5/parameter"], ["Riga", "192.168.72.9/parameter"], ["Prague", "192.168.112.7/parameter"]] While 1 For $_I = 1 To UBound ( $_CityArray ) -1 $_FilePath = "c:\ftp\" & $_CityArray[$_I][0] & "\1.txt" ConsoleWrite ( $_I & " $_FilePath : " & $_FilePath & @Crlf ) If FileExists ( $_FilePath ) Then RunWait ( 'c:\ftp\program\start.exe root:test@' & $_CityArray[$_I][1] ) $_Renamed = "c:\ftp\" & $_CityArray[$_I][0] & "\" & $_I +1 & ".txt" ConsoleWrite ( " $_Renamed : " & $_Renamed & @Crlf ) FileMove ( $_FilePath, $_Renamed ) EndIf Next For $_I = 1 To UBound ( $_CityArray ) -1 $_SearchPath = "c:\ftp\" & $_CityArray[$_I][0] ConsoleWrite ( " $_SearchPath : " & $_SearchPath & @Crlf ) Switch _CheckForJpegNumber ( $_SearchPath ) Case 1, 2, 3 FileMove ( $_SearchPath & '\2.txt', $_SearchPath & '\3.txt' ) Case Else ; EndSwitch Next WEnd Func _CheckForJpegNumber ( $_FolderPath ) $FileList = _FileListToArray ( $_FolderPath, '*.jpg' ) If @Error Then Return 0 $_NumberOfJpeg = UBound ( $FileList ) -1 Return $_NumberOfJpeg EndFunc AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
KennethF Posted April 16, 2011 Author Posted April 16, 2011 This error pop ups when i compile the exe file.. ? C:\FTP\AutoIT\Test5.au3(31,58) : ERROR: _FileListToArray(): undefined function. $FileList = _FileListToArray ( $_FolderPath, '*.jpg' )
Moderators Melba23 Posted April 16, 2011 Moderators Posted April 16, 2011 KennethF,Do you have#Include <File.au3>at the top of your script? 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
wakillon Posted April 16, 2011 Posted April 16, 2011 This error pop ups when i compile the exe file.. ?C:\FTP\AutoIT\Test5.au3(31,58) : ERROR: _FileListToArray(): undefined function. $FileList = _FileListToArray ( $_FolderPath, '*.jpg' )Each time you try a script you don't take it entire...Be carefull ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
KennethF Posted April 16, 2011 Author Posted April 16, 2011 (edited) Somehow the #.jpg continues to go one step up in even in different directories.. - Example.. If I put 1.exe into LONDON it changes to 2.txt. Then I put a 1.txt into PARIS and it changes to 3.txt (but it should have changed to 2.txt). Then I put 1.txt into MOSCOW but it changes to 4.txt (It should also only change to 2.txt)The txt file can only have three names.. - 1.txt or 2.txt or 3.txtMaybe its easier if I write the whole purpose of the programFor Paris:1. A truck in Paris runs onto a weight - once weighted a program (not this one) puts a file named 1.txt into the c:\ftp\paris directory2. This AUTOIT program (the one you are making for me) monitors all the city names for a file named 1.txt. When it sees the file c:\ftp\paris\1.txt it renames the filename to 2.txt and starts an external DOS exe file with some parameters. This program sends a TCP packet to an IP camera with alot of parameters (This program works if i just make one line in a DOS windows with all parameters.3. Every time the IP camera recieves the packet it will FTP a JPG image to the PARIS directory.4. When this AUTOIT program sees that there is ONE jpg file in the PARIS directory it renames the file 2.txt to 3.txt5. The program that placed the file 1.txt is still monitoring all the city name directories.. - When it sees a file named 3.txt it copies all the JPG files in the Paris directory and deletes all files including the 3.txt file.6. The Paris directory is now ready for another sequence again.For London:1. A truck in London runs onto a weight - once weighted a program (not this one) puts a file named 1.txt into the c:\ftp\london directory2. This AUTOIT program (the one you are making for me) monitors all the city names for a file named 1.txt. When it sees the file c:\ftp\london\1.txt it renames the file to 2.txt and starts an external DOS exe file with some parameters. This program sends a TCP packet to an IP camera with alot of parameters (This program works if i just make one line in a DOS windows with all parameters.In London however there is more than one camera. So the program needs to start the EXE file two times more with different IP adresses but same parameters.3. Every time any of the LONDON IP camera recieves the packet it will FTP a JPG image to the LONDON directory.4. When this AUTOIT program sees that there is three jpg file in the LONDON directory it renames the file 2.txt to 3.txt5. The program that placed the file 1.txt is still monitoring all the city name directories.. - When it sees a file named 3.txt it copies all the JPG files in the Paris directory and deletes all files including the 3.txt file.6. The LONDON directory is now ready for another sequence again.All this should happen for all 15 city names... :-)Hope I makes more sence now.. - and hoping you still want to help programming this for me.. :-)PS. Also if it is possible I would like a Window/program to be seen in Windows when this program runs.. - More so I can see that it is actually running - and If i choose I can close it.. :-)PS2. In the end when everything works a Nice feature that would be nice to have is that inside the program windows a state of all the city names would be displayed and a status saying NOTHING, 1.txt, 2.txt or 3.txt - that way it would be easy to see if everything is running smoothly.. :-)Best regards, Kenneth Edited April 16, 2011 by KennethF
wakillon Posted April 17, 2011 Posted April 17, 2011 wow ! I want well help you, but you must work a little bit !Post your script and i will try to help you, but i can't do all !I'm waiting for you. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
KennethF Posted April 17, 2011 Author Posted April 17, 2011 Hey - fair enough - but there was alot of variables I did not understand in your script - so I started from scratch and by looking at all your other scripts and some examples in the help file, I made this script.. - All I need to do now is write all the missing lines for the different cities.., maybe find out how to display status in a status windows and figure out how to show the program running so I can terminate it without using the taskmanager.. - but right now it looks like its working.. I really really really appreciate ALL your help !!! - It was a BIG help for me.. !!! Please look at the script and please comment.. :-) expandcollapse popupWhile 1 ;Comment: Check London to start image capture If FileExists ( 'c:\ftp\london\1.txt' ) Then Run ( 'c:\ftp\program\httpcmd.exe root:test@192.168.1.10') Filemove ( "c:\ftp\london\1.txt", "c:\ftp\london\2.txt", 0) EndIf ;Comment: Check Paris to start image capture If FileExists ( 'c:\ftp\paris\1.txt' ) Then Run ( 'c:\ftp\program\httpcmd.exe root:test@192.168.1.11') Run ( 'c:\ftp\program\httpcmd.exe root:test@192.168.1.12') Run ( 'c:\ftp\program\httpcmd.exe root:test@192.168.1.13') Filemove ( "c:\ftp\paris\1.txt", "c:\ftp\paris\2.txt", 0) EndIf ;Comment: Check London for JPG images If FileExists ( 'c:\ftp\london\*.jpg' ) Then FileMove ( "c:\ftp\london\2.txt", "c:\ftp\london\3.txt", 0) EndIf ;Comment: Check Paris for three JPG images $search = FileFindFirstFile("c:\ftp\paris\*.jpg") Local $Count=0 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $Count+=1 WEnd ; Close the search handle FileClose($search) IF $Count>=3 Then FileMove ( "c:\ftp\paris\2.txt", "c:\ftp\paris\3.txt", 0) EndIf WEnd
wakillon Posted April 17, 2011 Posted April 17, 2011 It looks good !I can't try it, and i don't know what is doing your httpcmd.exe, but may be you should use runwait instead of run ? AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
MvGulik Posted April 17, 2011 Posted April 17, 2011 "Checking for file"Failure: Returns 0 if path/file does not exist.Success: Returns 1. ... (if path/file does exist.) ... just in case you don't like to give that little pesty exception a change ... "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
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