aa2zz6

Copying files not working

8 posts in this topic

#1 ·  Posted

My script scans each drive for a folder called "My_pictures". Once that particular folder is found we then create a new folder in the destination path. Once that's created we use a dircopy to copy all the data to the new folder. But it doesn't seem to copy anything. Am I missing something?

; ---- stitch the file path together ----
            $GetPaths = $drive[$i] & "\my_pictures\"
            
            ; ---- Copy files from drives[$i] to destination folder ----
            DirCopy($GetPaths, $Destination,$FC_NOOVERWRITE)
#include <FileConstants.au3>
#include <Date.au3>

$drive = DriveGetDrive("ALL")
; ---- If an error doesn't occur ----
If Not @error Then
    ; ---- Create an array to scan each drive ----
    For $i = 1 To $drive[0]
        ; ---- C ----
        FileChangeDir($drive[$i])
        ; ---- Search for the folder ----
        Local $sFilePath = "my_pictures"
        Local $Destination = "S:\Digital Camera Photos\2017\"
        Local $iFileExists = FileExists($sFilePath)
        If $iFileExists Then
            MsgBox(0, "", "Drive " & $drive[$i] & $iFileExists)
            ; ---- Create a new folder for destination data ----
            DirCreate($Destination & _DateToMonth ( @MON, 1 ) & "-" & @MDAY & "-" & @YEAR & " " & @UserName)
            
            ; ---- stitch the file path together ----
            $GetPaths = $drive[$i] & "\my_pictures\"
            
            ; ---- Copy files from drives[$i] to destination folder ----
            DirCopy($GetPaths, $Destination,$FC_NOOVERWRITE)
            MsgBox(0, "", $GetPaths)
        Else
            ; ---- This list all the drives.. ----
            ;MsgBox(0, "", "The file doesn't exist." & @CRLF & "FileExist returned: " & $iFileExists)
        EndIf
    Next
EndIf

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You don't have too much error checking in there yet. :)
Wild guess though: shouldn't the last \ be removed in : $GetPaths = $drive[$i] & "\my_pictures\"

and be changed to $GetPaths = $drive[$i] & "\my_pictures" ?

Quote

Parameters

source dir Path of the source directory (with no trailing backslash). e.g. "C:\Path1"
dest dir Path of the destination dir (with no trailing backslash). e.g. "C:\Path_Copy"
flag [optional] this flag determines whether to overwrite files if they already exist:
    $FC_NOOVERWRITE (0) = (default) do not overwrite existing files
    $FC_OVERWRITE (1) = overwrite existing files

Constants are defined in FileConstants.au3.

Jos

 

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I removed the backslash and I added a few error handlers but the DirCopy() doesn't seem to be able to register files inside the folder even though it's not empty. The msgbox for $data = dircopy is coming back 0 so is it possible that the dircopy function isn't able to access data within drive letters such as j or h? 

 

Edit: I'm able to create a folder in the my_Pictures but I can't push out the data which is weird.

#include <FileConstants.au3>
#include <Date.au3>

$drive = DriveGetDrive("ALL")
; ---- If an error doesn't occur ----
If Not @error Then
    ; ---- Create an array to scan each drive ----
    For $i = 1 To $drive[0]
        ; ---- Change drives ----
        FileChangeDir($drive[$i])
        ; ---- Search for the folder ----
        Local $sFilePath = "my_pictures"
        Local $Destination = "S:\Digital Camera Photos\2017\"

        ; ---- stitch the file path together ----
        Local $GetPaths = $drive[$i] & "\my_pictures"
        Local $GetPaths1 = $GetPaths
        
        ; ---- Check if the folder has any information ----
        $sizefldr1 = DirGetSize($GetPaths1, 1)
        If Not @error Then
            If Not $sizefldr1[1] And Not $sizefldr1[2] Then
                MsgBox(0, "Msgbox", "Empty")
            Else
                MsgBox(0, "Msgbox", "Not empty: " & $GetPaths)
                ; ---- Create a new folder for destination data ----
                $folder = DirCreate($Destination & _DateToMonth(@MON, 1) & "-" & @MDAY & "-" & @YEAR & " " & @UserName)
                MsgBox(0, "", $folder)
                ; ---- Copy files from drives[$i] to destination folder ----
                $Data = DirCopy($GetPaths1, $Destination, $FC_NOOVERWRITE)
                MsgBox(0, "", $Data)
            EndIf
        Else
            MsgBox(0, "Msgbox", "Does not exist: " & $GetPaths)
        EndIf
    Next
EndIf

 

Untitled.png

Edited by aa2zz6

Share this post


Link to post
Share on other sites

#4 ·  Posted

@aa2zz6

I tried checking you code and I've found some issues.

1. $Destination must not contain "S:" or any directory since it was already declared in $drive[$i].

Local $Destination = "S:\Digital Camera Photos\2017\"

2. $sFilePath = "my_pictures" was duplicated with $drive[$i] & "\my_pictures".

Local $sFilePath = "my_pictures"
Local $GetPaths = $drive[$i] & "\my_pictures"

 

3. I tried it this way and removing DirCreate() function to see if it is working or not (and it worked accordingly). However, DirCreate() was removed.:sweating: By that, maybe you can check why it is not working when using DirCreate().^_^

#include <FileConstants.au3>
#include <Date.au3>

$drive = DriveGetDrive("ALL")
If Not @error Then
   For $i = 1 To $drive[0]
      Local $Destination = "\Digital Camera Photos\2017\"
         FileChangeDir($drive[$i])
         Local $GetPaths = $drive[$i] & "\my_pictures\"
         Local $GetPaths1 = $GetPaths
         $sizefldr1 = DirGetSize($GetPaths1, 1)
         If Not @error Then
            If Not $sizefldr1[1] And Not $sizefldr1[2] Then
               MsgBox(0, "Msgbox", "Empty")
            Else
;~             $folder = DirCreate($Destination & _DateToMonth(@MON, 1) & "-" & @MDAY & "-" & @YEAR & " " & @UserName) ; Error originate's here...
               DirCopy($GetPaths1, $Destination, $FC_OVERWRITE)
            EndIf
         Else
            MsgBox(0, "Msgbox", "Does not exist: " & $GetPaths1)
         EndIf
   Next
EndIf

Just trying to suggest. Hope it helps.:>

 

KS15

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted

15 hours ago, Jos said:

Parameters

source dir Path of the source directory (with no trailing backslash). e.g. "C:\Path1"
dest dir Path of the destination dir (with no trailing backslash). e.g. "C:\Path_Copy"
flag [optional] this flag determines whether to overwrite files if they already exist:
    $FC_NOOVERWRITE (0) = (default) do not overwrite existing files
    $FC_OVERWRITE (1) = overwrite existing files

Constants are defined in FileConstants.au3.

 

What's up with those backslashes still at the end of the Source & Target paths? :)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks for the help!

@Jos Does this look good for catching errors?  Still learning these error checks :sweating:

#include <FileConstants.au3>
#include <Date.au3>

$drive = DriveGetDrive("ALL")
If Not @error Then
    For $i = 1 To $drive[0]
        Local $Destination = "S:\Digital Camera Photos\2017\" & _DateToMonth(@MON, 1) & "-" & @MDAY & "-" & @YEAR & " " & @UserName
        FileChangeDir($drive[$i])
        Local $GetPaths = $drive[$i] & "\my_pictures\"
        Local $GetPaths1 = $GetPaths
        Local $CleanMyImages = $drive[$i] & "\my_pictures\"
        $sizefldr1 = DirGetSize($GetPaths1, 1)
        If Not @error Then
            If Not $sizefldr1[1] And Not $sizefldr1[2] Then
                ;MsgBox(0, "Drive", $GetPaths1 & " : " & "Empty")
            Else
                ;MsgBox(0, "Msgbox", "Found")
                $rc = FileExists($Destination)
                If $rc = 0 Then
                    MsgBox(0, "MsgBox", "File Path: " & $Destination & " : " & "Unavailable")
                    $rc1 = DirCreate($Destination)
                    If $rc1 = 0 Then
                        MsgBox(0, "Created - No", "File not created" & @CRLF & "Please see GIS Department")
                    Else
                        MsgBox(0, "Created - Yes", "File created: " & $Destination)
                        $rc2 = DirCopy($GetPaths1, $Destination, $FC_OVERWRITE)
                        If $rc2 = 0 Then
                            MsgBox(0, "Copied - No", "File not copied")
                        Else
                            MsgBox(0, "Copied - Yes", "Files copied" & " : " & $Destination)
                        EndIf
                        ; ---- Clean my_images folder ----
                        $rc4 = FileDelete($CleanMyImages)
                        If $rc4 = 0 Then
                            MsgBox(0, "Delete - No", "Failed to delete file" & " : " & $CleanMyImages)
                        Else
                            MsgBox(0, "Delete - Yes", "File deleted" & " : " & $CleanMyImages)
                        EndIf
                    EndIf
                Else
                    MsgBox(0, "MsgBox", "File Path: " & $Destination & " : " & "Available")
                    $rc2 = DirCopy($GetPaths1, $Destination, $FC_OVERWRITE)
                    If $rc2 = 0 Then
                        MsgBox(0, "Copied - No", "File not copied")
                    Else
                        MsgBox(0, "Copied - Yes", "Files copied" & " : " & $Destination)
                        ; ---- Clean my_images folder ----
                        $rc4 = FileDelete($CleanMyImages)
                        If $rc4 = 0 Then
                            MsgBox(0, "Delete - No", "Failed to delete files" & " : " & $CleanMyImages)
                        Else
                            MsgBox(0, "Delete - Yes", "Files deleted" & " : " & $CleanMyImages)
                        EndIf
                    EndIf
                EndIf
            EndIf
        Else
            ;MsgBox(0, "Msgbox", $GetPaths1 & " : " & " Does not exist")
        EndIf
    Next
EndIf

 

Edited by aa2zz6

Share this post


Link to post
Share on other sites

#7 ·  Posted

2 hours ago, aa2zz6 said:

Still learning these error checks :sweating:

Looking pretty extensive now, even reporting success there in every step. ......and more importantly........  does it work now? :)

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#8 ·  Posted

Yes, it works very well!

 

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