Jump to content

filecopy(), run() and exit


prohun
 Share

Recommended Posts

First of all, i would like to say that I'm somewhat of a newb in AutoIt, I haven't had much experience with it. I am trying to write a portable script that will go on my USB drive. I want to be able to run it from the USB and then have it copy itself into the @MyDocumentsDir of whatever computer i go on. It should then run that copy and quit the copy on the USB so that i can safely remove my USB from the computer.

Here's part of what I have:

#NoTrayIcon
AutoItSetOption("RunErrorsFatal", 0)

;Some HotKey stuff here
HotKeySet("{ESC}", "Quit")

;----- Copy self into my documents dir -----
$copy = IniRead("1.ini", "Main", "Copy", 0)
;I have 1.ini in the directory with the proper values
selfcopy()
Func selfcopy()
    If (@Compiled) And ($copy = 1) Then
        FileCopy(@ScriptFullPath, @MyDocumentsDir & @ScriptName, 1)
        Run(@ScriptName, @MyDocumentsDir)
        MsgBox(0, "ran copy", @error)
        If Not @error Then
            MsgBox(0, "trying to exit", @ScriptFullPath)
            Exit
        EndIf
    EndIf
EndFunc

main()
Func main()
;main function here
EndFunc

Func Quit()
    Exit
EndFunc

Func OnAutoItStart()
    MsgBox(0, "starting", @ScriptFullPath)
EndFunc

Func OnAutoItExit()
    MsgBox(0, "exited", @ScriptFullPath)
EndFunc

The problem I have is that it doesn't run the copy in the my documents dir, instead, it runs itself again, preventing my from removing my USB. As you can see, i have added the error testing stuff in each step to see exactly what is happening, yet i just cant seem to figure out what is wrong. Please help me spot and fix the error. Thanks in advance guys.

Link to comment
Share on other sites

First of all, i would like to say that I'm somewhat of a newb in AutoIt, I haven't had much experience with it. I am trying to write a portable script that will go on my USB drive. I want to be able to run it from the USB and then have it copy itself into the @MyDocumentsDir of whatever computer i go on. It should then run that copy and quit the copy on the USB so that i can safely remove my USB from the computer.

Here's part of what I have:

#NoTrayIcon
AutoItSetOption("RunErrorsFatal", 0)

;Some HotKey stuff here
HotKeySet("{ESC}", "Quit")

;----- Copy self into my documents dir -----
$copy = IniRead("1.ini", "Main", "Copy", 0)
;I have 1.ini in the directory with the proper values
selfcopy()
Func selfcopy()
    If (@Compiled) And ($copy = 1) Then
        FileCopy(@ScriptFullPath, @MyDocumentsDir & @ScriptName, 1)
        Run(@ScriptName, @MyDocumentsDir)
        MsgBox(0, "ran copy", @error)
        If Not @error Then
            MsgBox(0, "trying to exit", @ScriptFullPath)
            Exit
        EndIf
    EndIf
EndFunc

main()
Func main()
;main function here
EndFunc

Func Quit()
    Exit
EndFunc

Func OnAutoItStart()
    MsgBox(0, "starting", @ScriptFullPath)
EndFunc

Func OnAutoItExit()
    MsgBox(0, "exited", @ScriptFullPath)
EndFunc

The problem I have is that it doesn't run the copy in the my documents dir, instead, it runs itself again, preventing my from removing my USB. As you can see, i have added the error testing stuff in each step to see exactly what is happening, yet i just cant seem to figure out what is wrong. Please help me spot and fix the error. Thanks in advance guys.

Welcome to the forums!

The copy bit looks wrong, you need the backslash

FileCopy(@ScriptFullPath, @MyDocumentsDir & '\' & @ScriptName, 1)

Then check to make sure the file was copied there.

Before you run the script add

FileChangeDir(@DocumentsCommonDir)

Then you need to see if the script is installed already so you can run it again, so have something like

if StringInStr(@ScriptFullPath, @MyDocumentsDir) then
  ; don't do the copy bit
else
  ; do the copy bit and exit
endif
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...