Jump to content

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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!


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...