PraveenKumarNatarajan Posted December 21, 2019 Share Posted December 21, 2019 I am able to open a notepad file with the help of AutoIt and able to pass some text and save the text document successfully. Given below is the code I have used for it : Run("C:\WINDOWS\System32\notepad.exe") Sleep(2000) Send("Hell+o") Sleep(3000) WinClose("Untitled - Notepad") WinWaitActive("Notepad") Sleep(3000) Send("{ENTER}") WinWaitActive("Save As") Send("sample.txt") Sleep(1000) Send("{TAB}") Sleep(1000) Send("{TAB}") Sleep(1000) Send("{TAB}") Sleep(1000) Send("{TAB}") Sleep(1000) Send("{ENTER}") How should I handle the conditional part in the code like if the file with the specified name already exists, then I should handle the "Confirm Save As" popup by providing the command as 'Yes' else if the file with the specified name is not present in the path, then should directly save it. What to add to the above code, can somone please help? Link to comment Share on other sites More sharing options...
Nine Posted December 21, 2019 Share Posted December 21, 2019 Read about FileExists () function in help file. You could simply check if the file exists and then go the proper way to save the file. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Subz Posted December 21, 2019 Share Posted December 21, 2019 Why use Notepad when you can use FileOpen/FileWrite, with FileOpen you can decided whether to append or overwrite the file. Link to comment Share on other sites More sharing options...
jdelaney Posted December 22, 2019 Share Posted December 22, 2019 WinWait With a defined timeout. 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 More sharing options...
abberration Posted December 22, 2019 Share Posted December 22, 2019 Re-creating what you want in your sample code, this should work (at least, I think): $data = "Hell+o" & @CRLF & "{TAB}" & "{TAB}" & "{TAB}" & "{TAB}" & "{ENTER}" If NOT FileExists("sample.txt") Then FileWrite("sample.txt", $data) EndIf I hope this will help guide you towards better coding. If you need better explanations, feel free to ask. If I am not around to help, there are many geniuses here that can help. If you tell us what you are trying to accomplish instead of pseudo code, maybe we can point you into a better direction. Best wishes! Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
markyrocks Posted December 23, 2019 Share Posted December 23, 2019 this kinda looks to see if the file exists and then just keeps adding a digit at the end to keep making additional files depending if the file its trying to write exists or not. lol i accidentally made 999 files on my desktop messing around with this so be careful lol. that was fun. $data = "Hell+o" & @CRLF & "{TAB}" & "{TAB}" & "{TAB}" & "{TAB}" & "{ENTER}" for $x=1 to 10 ;or a million? If FileExists("sample.txt")=0 Then FileWrite("sample.txt", $data) ExitLoop Elseif Not FileExists("sample_" & $x & ".txt") Then FileWrite("sample_" & $x & ".txt", $data) ExitLoop EndIf Next Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" 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