Jump to content

DirCreate and FileCopy


James
 Share

Recommended Posts

Who ever knew, DirCreate and FileCopy would be so hard?

JK, I can do it. But not on this :S

#include <GUIConstants.au3>

$Window = GUICreate("BetaPad Installer | Beta 1.0 Installer", 476, 56, @DesktopHeight / 2.5, @DesktopWidth / 4)
$Location = GUICtrlCreateInput("", 8, 16, 257, 21)
$Locate = GUICtrlCreateButton("Location to install", 272, 16, 97, 25, 0)
$Install = GUICtrlCreateButton("Install", 376, 16, 89, 25, 0)

GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Locate
            $var = FileSelectFolder("Choose a folder to install to.", "", 5)
            GUICtrlSetData($Location, $var)
        Case $Install
            DirCreate($Location)
            DirCreate($Location & "\Docs")
            FileInstall(@ScriptDir & "\Files\AVE2.exe", $Location, 1)
            FileInstall(@ScriptDir & "\Docs\readme.txt", $Location, 1)
    EndSwitch
WEnd

No errors are given, but the files and Docs folder is not made.

Secure

Link to comment
Share on other sites

Who ever knew, DirCreate and FileCopy would be so hard?

JK, I can do it. But not on this :S

#include <GUIConstants.au3>

$Window = GUICreate("BetaPad Installer | Beta 1.0 Installer", 476, 56, @DesktopHeight / 2.5, @DesktopWidth / 4)
$Location = GUICtrlCreateInput("", 8, 16, 257, 21)
$Locate = GUICtrlCreateButton("Location to install", 272, 16, 97, 25, 0)
$Install = GUICtrlCreateButton("Install", 376, 16, 89, 25, 0)

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Locate
            $var = FileSelectFolder("Choose a folder to install to.", "", 5)
            GUICtrlSetData($Location, $var)
        Case $Install
            DirCreate($Location)
            DirCreate($Location & "\Docs")
            FileInstall(@ScriptDir & "\Files\AVE2.exe", $Location, 1)
            FileInstall(@ScriptDir & "\Docs\readme.txt", $Location, 1)
    EndSwitch
WEnd

No errors are given, but the files and Docs folder is not made.

Secure

use message boxes to check your values... $location contains the control id of the location edit box, not its contents. check out GUICtrlRead()
Link to comment
Share on other sites

Who ever knew, DirCreate and FileCopy would be so hard?

JK, I can do it. But not on this :S

#include <GUIConstants.au3>

$Window = GUICreate("BetaPad Installer | Beta 1.0 Installer", 476, 56, @DesktopHeight / 2.5, @DesktopWidth / 4)
$Location = GUICtrlCreateInput("", 8, 16, 257, 21)
$Locate = GUICtrlCreateButton("Location to install", 272, 16, 97, 25, 0)
$Install = GUICtrlCreateButton("Install", 376, 16, 89, 25, 0)

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Locate
            $var = FileSelectFolder("Choose a folder to install to.", "", 5)
            GUICtrlSetData($Location, $var)
        Case $Install
            DirCreate($Location)
            DirCreate($Location & "\Docs")
            FileInstall(@ScriptDir & "\Files\AVE2.exe", $Location, 1)
            FileInstall(@ScriptDir & "\Docs\readme.txt", $Location, 1)
    EndSwitch
WEnd

No errors are given, but the files and Docs folder is not made.

Secure

That d****d FileInstall has caused me enough grief.

First off, from the help file

You can not use a Variable in the FileInstall(). This also invariably applies to macros as well. Just use FileInstall("\Files\AVE2.exe", $Location, 1)

Second

I would just use the FileInstall to install the file to the @TempDir and then use FileMove() with the flag set to 9 (Overwrite + create folder struc) to put the file where you want it.

You may also have to use quotes or FileGetShortName() for $Location.

And I think (just for safety) add a backslash at the end of $Location ......... $Location = $Location & '\'

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

This work for me.

#include <GUIConstants.au3>

Local $var

$Window = GUICreate("BetaPad Installer | Beta 1.0 Installer", 476, 56, @DesktopHeight / 2.5, @DesktopWidth / 4)
$Location = GUICtrlCreateInput("", 8, 16, 257, 21)
$Locate = GUICtrlCreateButton("Location to install", 272, 16, 97, 25, 0)
$Install = GUICtrlCreateButton("Install", 376, 16, 89, 25, 0)

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Locate
            $var = FileSelectFolder("Choose a folder to install to.", "", 5)
            GUICtrlSetData($Location, $var)
        Case $Install
            if $var = '' Then 
                MsgBox(64,"Warning","You need to select a folder to install to.")
                ContinueLoop
            EndIf
            DirCreate($var)
            DirCreate($var & "\Docs")
            FileInstall(".\Files\AVE2.exe", $var & '\', 1)
            FileInstall(".\Docs\readme.txt", $var & '\', 1)
    EndSwitch
WEnd

Like GEOsoft mention "you can not use a Variable in the FileInstall()". That is true for the source section of fileinstall but you can use variable at destination section.

To make your script works.

1) Replace @ScriptDir for .

2) you were using variable $location which only hold the value of Control ID "GUICtrlCreateInput" and not the full path where you want to make the install. So in FileInstall() change $location for $var and add trailing backslash.

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Thanks danny..

Why do you replace @ScriptDir with . ? I don't get that.

Read this link if you want to learn the basic of internal directory structure, but basically...

Every regular directory on the disk has two special entries. These are named "." (single dot), which refers to the current directory, and ".." (double dot), which refers to the parent directory.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

This won't help me. What is not working or show the new code? :">

The code I add on post #6 work fine on my computer winxp sp2.

Your example suffers the same problem as the intial topic starter. You need to read the control with GuiCtrlRead to get the information else any typed path inserted into the input control is ignored.

#include <GUIConstants.au3>

$Window = GUICreate("BetaPad Installer | Beta 1.0 Installer", 476, 56, @DesktopHeight / 2.5, @DesktopWidth / 4)
$Location = GUICtrlCreateInput("", 8, 16, 257, 21)
$Locate = GUICtrlCreateButton("Location to install", 272, 16, 97, 25, 0)
$Install = GUICtrlCreateButton("Install", 376, 16, 89, 25, 0)

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Locate
            $var = FileSelectFolder("Choose a folder to install to.", "", 5)
            If Not @error Then
                GUICtrlSetData($Location, $var)
            EndIf
        Case $Install
            $path = GUICtrlRead($Location)
            If $path = '' Then
                MsgBox(64, "Warning", "You need to select a folder to install to.")
            ElseIf DirCreate($path) And DirCreate($path & "\Docs") Then
                FileInstall(".\Files\AVE2.exe", $path & '\', 1)
                FileInstall(".\Docs\readme.txt", $path & '\', 1)
            Else
                MsgBox(64, "Warning", "Install failed.")
            EndIf
    EndSwitch
WEnd

:P

Link to comment
Share on other sites

@MHZ The only reason I didn't use GUICtrlRead() is becasue Secure_ICT already has the path information in $var = FileSelectFolder("Choose a folder to install to.", "", 5). I didn't see the point of using GUICtrlRead() to get the path when $var already has the path, but thanks for the little tip it never cross my mind of using fileinstall() between ElseIf DirCreate($path) And DirCreate($path & "\Docs") Then Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
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...