Sign in to follow this  
Followers 0
Reload_2006

Ok, seriously, why can't I get this basic code to execute?

12 posts in this topic

I have a basic test script to test why this code won't work. Below is the code:

DirCopy ("C:\Temp\testfile", "C:\temp\output",0)

I want it to copy the testfile directory to the output directory. So in the end I want to have the C:\temp\output\testfile directory and all of its contents. But for the life of me, I can't get this basic code to execute. Am I just overlooking something REALLY obvious to anyone else? This is pretty simple, so I really don't know what could possibly be wrong.

I'm using AutoIt v3.2.01 and AutoIt v3.2.1.12 (Beta).

Share this post


Link to post
Share on other sites



Should work if c:\temp\testfile exists.

What is returned by:

ConsoleWrite(DirCopy("C:\Temp\testfile", "C:\temp\output",0))

I tried with 3.2.1.12.;)

Share this post


Link to post
Share on other sites

With the overwrite flag being 0, the function does not work if the destination folder exists (even if it is empty).

Change the overwrite flag to 1, or delete the folder "C:\temp\output".


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

hmm, your right stumpii.

But I think th help file is a little bit missleading as it says:

Remarks

If the destination directory structure doesn't exist, it will be created (if possible).

Althought it is correct it also does make you think that the function will work even if the folder exists, does it not?

Share this post


Link to post
Share on other sites

hmm, your right stumpii.

But I think th help file is a little bit missleading as it says:

Althought it is correct it also does make you think that the function will work even if the folder exists, does it not?

Not if the overwrite flag is set to zero, then it won't overwrite the folder, and therefore can't create one.

At least thats what i get... ;)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

With the overwrite flag being 0, the function does not work if the destination folder exists (even if it is empty).

Change the overwrite flag to 1, or delete the folder "C:\temp\output".

That's it Stumpii!!! See it's stuff like that that makes me pull my hair out. I looked at the help file, read it, and read it some more and the flag I was using SEEMED to be valid. I knew it was something simple like that. :|

And onto my last problem. If you guys can help me with this one, my script will be complete. It is the last hurdle I have.

Here's the thing. While the directory is being copied (potentially several gigs), I want a progress meter to be displayed.

$bLoop = 1
While $bLoop = 1
    $text = InputBox("Backup application", "Please enter your Windows username.")
         If @error Then Exit
    $search = FileFindFirstFile("C:\Documents and Settings\" & $text)
         If $search = -1 Then
              MsgBox(4096, "Error", "Profile not found. Please try again!")
         Else
    $answer = MsgBox(4, "Successful", "Directory found. Would you like to backup your profile now?")
         If $answer = 7 Then    
         Exit
         EndIf   
    $bLoop = 0
    $path1 = FileSelectFolder("Please select your destination directory", "", 1)
    DirCopy ($search, $path1,1) 
    Exit
    EndIf
WEnd
FileClose($search)

Here is the piece of code I was going to append to the directory copy, but I don't think it will work because it is for FileCopy:

Func _FileCopy($fromFile,$todirectory) 
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($todirectory).CopyHere($fromFile)
EndFunc

What do you guys think?

Edited by Reload_2006

Share this post


Link to post
Share on other sites

Here is the piece of code I was going to append to the directory copy, but I don't think it will work because it is for FileCopy:

It is a general copy method

$path1 = FileSelectFolder("Please select your destination directory", "", 1)
If @error Then Exit
_FileCopy("C:\Temp\testfile\", $path1)

Func _FileCopy($fromFile,$todirectory)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($todirectory).CopyHere($fromFile)
EndFunc

;)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I tried to use it as a general copy, but it would error out on me. Here is the full code:

$bLoop = 1
While $bLoop = 1
    $text = InputBox("Backup application", "Please enter your Windows username.")
    If @error Then Exit
        
    $search = FileFindFirstFile("C:\Temp\" & $text)
         If $search = -1 Then
              MsgBox(4096, "Error", "Profile not found. Please try again!")
    Else
    $answer = MsgBox(4, "Successful", "Directory found. Would you like to backup your profile now?")
         If $answer = 7 Then    
         Exit
         EndIf   
    $bLoop = 0
    $path1 = FileSelectFolder("Please select your destination directory", "", 1)
    If @error Then Exit
    _FileCopy($search, $path1,1)

    Func _FileCopy($fromFile,$todirectory)
      Local $FOF_RESPOND_YES = 16
      Local $FOF_SIMPLEPROGRESS = 256
      $winShell = ObjCreate("shell.application")
      $winShell.namespace($todirectory).CopyHere($fromFile)
    EndFunc
    
    Exit
    EndIf
WEnd

FileClose($search)
Edited by Reload_2006

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Error. Tidy considers it also

$bLoop = 1
While $bLoop = 1
    $text = InputBox("Sterling backup application", "Please enter your Windows username.")
    If @error Then Exit

    $search = FileFindFirstFile("C:\Temp\" & $text)
    If $search = -1 Then
        MsgBox(4096, "Error", "Profile not found. Please try again!")
    Else
        $answer = MsgBox(4, "Successful", "Directory found. Would you like to backup your profile now?")
        If $answer = 7 Then
            Exit
        EndIf
        $bLoop = 0
        [b]$path1 = FileSelectFolder("Please select your destination directory", "", 1)
        If @error Then Exit
        _FileCopy($search, $path1, 1)

;### Tidy Error -> if Not closed before "Func" statement.
;### Tidy Error ->  & CHR$(34) & FIRSTWORD$ & " cannot be inside any IF/Do/While/For/Case/Func statement.
        Func _FileCopy($fromFile, $todirectory)
            Local $FOF_RESPOND_YES = 16
            Local $FOF_SIMPLEPROGRESS = 256
            $winShell = ObjCreate("shell.application")
            $winShell.namespace ($todirectory).CopyHere ($fromFile)
            EndFunc[ / b]

            Exit
;### Tidy Error -> "endif" is closing previous "func"
        EndIf
;### Tidy Error -> "wend" is closing previous "if"
    WEnd

    FileClose($search)
oÝ÷ Ù*&x*+­ç-ì§^jëh×6
$bLoop = 1
While $bLoop = 1
    $text = InputBox("Sterling backup application", "Please enter your Windows username.")
    If @error Then Exit

    $search = FileFindFirstFile("C:\Temp\" & $text)
    If $search = -1 Then
        MsgBox(4096, "Error", "Profile not found. Please try again!")
    Else
        $path = FileFindNextFile($search)
        If Not @error Then
            $answer = MsgBox(4, "Successful", "Directory found. Would you like to backup your profile now?")
            If $answer = 7 Then
                Exit
            EndIf
            $bLoop = 0
            $path1 = FileSelectFolder("Please select your destination directory", "", 1)
            If @error Then Exit
            _FileCopy($search, $path1, 1)
        Else
            MsgBox(0x40030, 'Failed', 'Could not continue')
            ExitLoop
        EndIf
        FileClose($search)
    EndIf
WEnd

Func _FileCopy($fromFile, $todirectory)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace ($todirectory).CopyHere ($fromFile)
EndFunc

Exit

Edit: added option to exit the loop.

Edited by MHz

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thank you so much for your help MHz. And thanks for cleaning up my code. ;) Unfortunately, I get the following error when the script hits the _FileCopy line (Line 33 to be more specific). Here's the error:

Line 33 ("C:\scraps\test.au3")

_FileCopy($search, $path1, 1)

_FileCopy($search, $path1, ^ ERROR

Error: Incorrect number of parameters in function call.

I just copied the second set of code ("Some Corrections made") you posted and that was the error I got. Any ideas why?

Edited by Reload_2006

Share this post


Link to post
Share on other sites

Error. Tidy considers it also

;...
            _FileCopy($search, $path1, 1)
;...

Func _FileCopy($fromFile, $todirectory)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace ($todirectory).CopyHere ($fromFile)
EndFunc

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

You are calling the _FileCopy UDF with 3 parameters instead of 2 parameters. Remove the last parameter from the function call.

2 parameters like below.

_FileCopy($search, $path1)
Thanks MHz for all your help. Unfortunately, for some reason, the script will not copy the source directory ($search) to the destination directory ($path1). Do you have any ideas what the problem could be. I've looked through the code and everything looks fine. It will just not copy the content of the source folder. ;)

Below is the code I'm using.

$bLoop = 1
While $bLoop = 1
    $text = InputBox("Backup application", "Please enter your Windows username.")
    If @error Then Exit

    $search = FileFindFirstFile("C:\Temp\" & $text)
    If $search = -1 Then
        MsgBox(4096, "Error", "Profile not found. Please try again!")
    Else
        $path = FileFindNextFile($search)
        If Not @error Then
            $answer = MsgBox(4, "Successful", "Directory found. Would you like to backup your profile now?")
            If $answer = 7 Then
                Exit
            EndIf
            $bLoop = 0
            $path1 = FileSelectFolder("Please select your destination directory", "", 1)
            If @error Then Exit
            _FileCopy($search, $path1)
        Else
            MsgBox(0x40030, 'Failed', 'Could not continue')
            ExitLoop
        EndIf
        FileClose($search)
    EndIf
WEnd

Func _FileCopy($fromFile, $todirectory)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace ($todirectory).CopyHere ($fromFile)
EndFunc
Exit

Like I said, it is a quick test I'm running. I have a directory named testfile and output in C:\Temp. It simply needs to copy the content of testfile to output. Note, I'm just using these directories as tests.

Any help would be greatly appreciated!!

Edited by Reload_2006

Share this post


Link to post
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
Sign in to follow this  
Followers 0