Jump to content

Using FileSelect to copy files/dirs?


Recommended Posts

I'm wondering if you can use fileselect to copy files/dirs? My guess is no. I want to be able to select files/folders to copy to a directory that the user had picked earlier. Here's my (unfinished) code. Eventually I'd like to move it to a GUI, but for now it's more like a script.

thanks,

Ryan

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1.97
; Author:        Ryan Grelck <rgrelck@bjc.org>
;
; Script Function:
;   Create directory structure needed for the SMT
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here

Dim $maindir = "r:\ryan\test", $sourcedir = "R:\ryan\script\directory"
$FolderSelect = FileSelectFolder("Choose a folder." & @CRLF & "If your folder is not there, please create a new folder. Once created, rename that folder by pressing F2", $maindir, 1)
If @error = 1 then Exit
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(8739,"","You chose " & $FolderSelect & @CRLF & "Is your directory new?")
Select
    Case $iMsgBoxAnswer = 6;Yes
        MsgBox(0, "", "Creating new structure for you.")
        DirCopy($sourcedir, $FolderSelect, 1);when copying with dircopy, there must not be a trailing \ for this function to work correctly
        MsgBox(0, "", "Done creating new structure.", 2)
    Case $iMsgBoxAnswer = 7;No
        
    Case $iMsgBoxAnswer = 2;Cancel
        MsgBox(0, "", "You have cancelled the process, have a nice day.")
        Exit
EndSelect

;copy the source files from source
$MsgBoxSourceFiles = MsgBox(8739, "", "Do you have (new) source files?")
    If $MsgBoxSourceFiles = 6 Then; yes
        $message = "OK, where are the files located?"
        $files = FileOpenDialog($message, "R:\", "All Files (*.*)", 1 + 4 )
        If @error Then
            MsgBox(4096,"","No File(s) chosen")
        Else
            $files = StringReplace($files, "|", @CRLF)
            MsgBox(4096,"","You chose " & $files & "copying now.")
            FileCopy($files, $FolderSelect, 8)
        EndIf
        Exit
    ElseIf $MsgBoxSourceFiles = 7 Then; no
        MsgBox(0,"", "Why don't you have any source files?" & @CRLF & "Ending program.")
        Exit
    EndIf
MsgBox(0, "test", "test for debugging process to see if there is a proper exit.")
Link to comment
Share on other sites

  • Moderators

Well you can use it to copy Directories and all the files within it:

$var = FileSelectFolder("Choose a folder.", "")
DirCopy($var, @DesktopDir & "\TestCopy\My Documents", 1)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Well you can use it to copy Directories and all the files within it:

$var = FileSelectFolder("Choose a folder.", "")
DirCopy($var, @DesktopDir & "\TestCopy\My Documents", 1)
the issue I have with that, is that we don't always need the full directories, sometimes only specific files/directories within.
Link to comment
Share on other sites

  • Moderators

Then my suggestion to you is to use, FileOpenDialog() rather than FileFindFolder() << Is not looking for Files.

Edit:

Of course ^^ that made no sense... I had a thought, and just stopped typing...

You're using MsgBox(4) (yes or no), If your giving the end-user control to pick a file or folder, or you know if it's a file or folder that they should open, you could just use an If/Then statement... or a custom GUI for the specific task of looking for a file or folder.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Then my suggestion to you is to use, FileOpenDialog() rather than FileFindFolder() << Is not looking for Files.

that's what I'm using, but I'm not sure how to get it to copy the selected files. Would I have to toss it to a temp text file or something? Or can it copy it from the variables?

Link to comment
Share on other sites

  • Moderators

If you use a variable like:

$Var = FileSelectFolder() or

$Var = FileOpenDialog()

Both of those variables will hold the full path to what it is you've chosen to copy... I suggest you test it yourself... try both these codes.

$VarOne = FileSelectFolder("Choose a folder.", "")
MsgBox(4, 'Is This Correct?', $VarOne)

$VarTwo = FileOpenDialog("Choose A File", @ScriptDir, "All Files (*.*)")
MsgBox(4, 'Is This Correct?', $VarTwo)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

preferrably I'd like to be able to select multiple files/folders and copy those that I selected (including recursively copying the selected folders). I tried the scripts, but I was unable to get them to select the folder and files.

Edited by Ryan Grelck
Link to comment
Share on other sites

  • Moderators

preferrably I'd like to be able to select multiple files/folders and copy those that I selected (including recursively copying the selected folders). I tried the scripts, but I was unable to get them to select the folder and files.

Right, one selects folders, the other selects files. To do what you want, you'd need to write your own UDF, or search to see if one already exists. Sounds like you'll be doing GUI work this way anyway. Good Luck to you.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Right, one selects folders, the other selects files. To do what you want, you'd need to write your own UDF, or search to see if one already exists. Sounds like you'll be doing GUI work this way anyway. Good Luck to you.

yeah, I was afraid of that :P Oh well, time to create a UDF I guess lol. I don't remember seeing one created that does what I'd like. Thanks for the help smoke

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