Exit function [Solved]

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] Share this post Link to post 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.

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

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

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.

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.

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

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
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

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.

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]

Create an account

Register a new account