Jump to content

Exit function [Solved]


 Share

Recommended Posts

If my file doesn't exist I want my script to quit running. I *thought* that was what I coded, however when 'E:\results-1.htm' is missing I get the correct message but then it goes to the next part of the code. What am I doing wrong?

;check for jump drive
if NOT FileExists("E:\results-1.htm") then
    MsgBox(0, "ERROR!", "E:\results-1.htm dos not exist!")
    Exit
EndIf

;upload the file to the website, replacing the current file
$foo = FileCopy("E:\results-1.htm", $webPath & $file, 1)
if $foo = 0 then
    MsgBox(0, "ERROR!", "Backup not created")
    Exit
EndIf

MsgBox(0, $file, "upload complete")
Edited by muncherw
Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

If my file doesn't exist I want my script to quit running. I *thought* that was what I coded, however when 'E:\results-1.htm' is missing I get the correct message but then it goes to the next part of the code. What am I doing wrong?

;check for jump drive
if NOT FileExists("E:\results-1.htm") then
    MsgBox(0, "ERROR!", "E:\results-1.htm dos not exist!")
    Exit
EndIf

;upload the file to the website, replacing the current file
$foo = FileCopy("E:\results-1.htm", $webPath & $file, 1)
if $foo = 0 then
    MsgBox(0, "ERROR!", "Backup not created")
    Exit
EndIf

MsgBox(0, $file, "upload complete")
There is no way for that code to show the "does not exist" message and then NOT exit. So either you are misinterpreting what is happening or this is not the code you are running.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

;check for jump drive
if FileExists("C:\test.txt") = 0 then
    MsgBox(0, "ERROR!", "C:\test.txt does not exist!")
    Exit
EndIf

;upload the file to the website, replacing the current file
$foo = FileCopy("C:\test.txt", "C:\text backup.txt", 1)
if $foo = 0 then
    MsgBox(0, "ERROR!", "Backup not created")
    Exit
EndIf

MsgBox(0, "C:\test.txt", "upload complete")

i have just tested that and it works perfectly, maybe your computer is injecting itself while your not looking, it can happen :P

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Link to comment
Share on other sites

...maybe your computer is injecting itself while your not looking, it can happen :(

Code injection... with dirty needles... that's how computers get viruses.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I would write it more like this...

*** NOT TESTED

;check for file
If Not FileExists("C:\test.txt") Then
 MsgBox(0, "ERROR!", "C:\test.txt does not exist!")
Else; copy file
 If FileCopy("C:\test.txt", "C:\text backup.txt", 1) Then
  MsgBox(0, "C:\test.txt", "upload complete")
 Else; If copy fails
  MsgBox(0, "ERROR!", "Backup not created")
 EndIf
EndIf
Exit

However, as noted by Salty, this is not related to a website upload

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

There is no way for that code to show the "does not exist" message and then NOT exit. So either you are misinterpreting what is happening or this is not the code you are running.

:P

Coming at it today with a freshly rested brain I find that I was looking at the wrong lines of code. Before what I showed you was where I did the backup which obviously comes before the Exit function. I showed the code after it thinking it (which is quite similar but not the same) thinking it was the other section. Silly mistake...maybe when I'm not looking the computer was injecting *me* with dirty code! Thanks everybody.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...