Jump to content

DirCopy not working.. HELP!


Go to solution Solved by swstrau118,

Recommended Posts

I am trying to copy a folder from the C drive to a network drive, everything works perfectly except when I am trying to copy the folder SysDat it only copies the files with in the folder and pastes it into the Network drive. Please help

This is the part of code I am have trouble with:

Case $msg = $Button_2
            CopyWithProgress("C:\VSM\SysDat\", "\\networkdrive\c$\TEST\")
            ;MoveWithProgress("\\networkdrive\c$\TEST\GPData\", "\\networkdrive\c$\TEST\GPData " & @Year & " - " & @Min)
            ;MoveWithProgress("\\networkdrive\c$\TEST\SysDat\", "\\networkdrive\c$\TEST\SysDat " & @Year & " - " & @Min)

Also I am trying to write an If statement that will look at the folder before copying and if it sees the folders Sysdat and GPData then continue function else if SysDat and GPData contain any more characters do not copy them and only copy the two folders that do not have any additional characters. 

Also an if statement that looks at the Folders date and if you are to copy a folder that has a older date and paste it over to another networkdrive that has a newer folder date have a popup box stating are you sure you want to do this, if yes then continue else Stop. Below is the if statement I made that doesn't work:

Case $msg = $Button_1
            if stringupper(StringLeft("SysDat",6)) = "SysDat" Then 
                CopyWithProgress("C:\VSM\SYSDAT", "C:\VSM\SYSDAT " & @Year & " - " & @Min)
                CopyWithProgress("C:\VSM\GPData", "C:\VSM\GPData " & @Year & " - " & @Min)
                Else
                MsgBox(4096, "Error", "Stopping process")
            EndIf

Attached is the full code - any help is greatly appreciated!

Thanks!

Test2.au3

Link to comment
Share on other sites

I'm not on a network, so I may not be able to help you very much.  That said, have you checked what permissions are set on the folders?  Can you copy them directly using a hard-coded test?
 
For the IF statement you want to write, are you saying you want to copy the folders that are named exactly "SysDat" or "GPData" while ignoring a folder such as "SysDatTemp001"? Is the program going to find the folders, or will it take user input?

Link to comment
Share on other sites

  • Moderators

Hi, swstrau118. For what it is worth, your script works when I test on both XP and WIN7, so if it is not copying to the network drive the cause is something local to your machine (permissions on the folder you're copying, permissions on the network share, etc. etc.)

As for the IF statement, to only pull SysDat and GPData (not GPData 1988, etc.), your statement as is should work - e.g. CopyWithProgress("C:VSMSysDat" is not going to copy any directory with a name longer that SysDat.

Regarding the dates, you could always read the list of directories in using Melba's _RecFileListToArray, then run through the array with FileAttribute to get your dates, like so:

#include <Array.au3>
#include <RecFileListToArray.au3>

$sPath = "C:\Test"
$aDirs = _RecFileListToArray($sPath, "*", 0, 1, 1, 2)

    For $i = 1 To $aDirs[0]
        MsgBox(4096, "", FileGetTime($aDirs[$i], 1, 1))
    Next

You could do an If statement based on the file name, and compare the timestamps to get what you want.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I'm not on a network, so I may not be able to help you very much.  That said, have you checked what permissions are set on the folders?  Can you copy them directly using a hard-coded test?

 

For the IF statement you want to write, are you saying you want to copy the folders that are named exactly "SysDat" or "GPData" while ignoring a folder such as "SysDatTemp001"? Is the program going to find the folders, or will it take user input?

 

Yup I want it only to copy the exact Folders GPData and SysDat and ignore anything else such as " "SysDatTemp001" but I can't figure out how to write the if statement

Link to comment
Share on other sites

Hi, swstrau118. For what it is worth, your script works when I test on both XP and WIN7, so if it is not copying to the network drive the cause is something local to your machine (permissions on the folder you're copying, permissions on the network share, etc. etc.)

As for the IF statement, to only pull SysDat and GPData (not GPData 1988, etc.), your statement as is should work - e.g. CopyWithProgress("C:VSMSysDat" is not going to copy any directory with a name longer that SysDat.

Regarding the dates, you could always read the list of directories in using Melba's _RecFileListToArray, then run through the array with FileAttribute to get your dates, like so:

#include <Array.au3>
#include <RecFileListToArray.au3>

$sPath = "C:\Test"
$aDirs = _RecFileListToArray($sPath, "*", 0, 1, 1, 2)

    For $i = 1 To $aDirs[0]
        MsgBox(4096, "", FileGetTime($aDirs[$i], 1, 1))
    Next

You could do an If statement based on the file name, and compare the timestamps to get what you want.

Maybe you're right and I don't have the correct permissions. Because it will copy the contents of the folder but not the actual folder itself so I will when I go into the networkdrive Y:TEST it copes all the files with in SysDat and GPData but not the folders itsself. Do you think that still is an permission issue?

With the Dates, how can you get an IF statement to not copy over a file that has a newer date unless you say "YES".

Link to comment
Share on other sites

Yup I want it only to copy the exact Folders GPData and SysDat and ignore anything else such as " "SysDatTemp001" but I can't figure out how to write the if statement

So, is the program finding the folders, or is the user? Either way, use FileGetAttrib to know if you're looking at a folder or a file. The pseudo-code will be something like:

 

IF FileName = "GPData" And StringInStr(FileGetAttrib("filename"), "D") > 0 THEN
    Copy File
ENDIF
 

 

 

...

With the Dates, how can you get an IF statement to not copy over a file that has a newer date unless you say "YES".

Use the FileGetTime function.  See the help file.  Your pseudo-code will be something like:

 

IF Date is Newer Then
    Copy File
ELSE
    Ask User
ENDIF
Putting these together, you get:

IF FileName = "GPData" And StringInStr(FileGetAttrib("filename"), "D") > 0 THEN
    IF Date is Newer Then
        Copy File
    ELSE
        Ask User
    ENDIF
ENDIF
Edited by Artisan
Link to comment
Share on other sites

  • Solution

Thanks to everyone for all the help! I actually figured out a code that worked pretty well.

This code does the _FileCompare and I'm using IF statments to work it out.

If (_FileCompare("Z:\TEST\SysDat", "Y:\TEST\SysDat") = 1)  OR (_FileCompare("Z:\TEST\SyDat", "Y:\TEST\SysDat") = 0) Then
                    If MsgBox ( 4, "Overwrite Warning", "The files you are about to copy are older than the ones you will overwrite.  Proceed anyway?") = $IDYES then
                        MoveWithProgress("Y:\TEST\SysDat", "Y:\TEST\SysDat " & @Year & " - " & @Min)
                        CopyWithProgress("Z:\TEST\SysDat", "Y:\TEST\SysDat")
                    Else
                        MsgBox ( 1, "Operation Cancelled", "No files will be copied.")
                    EndIf
            Else

                    MoveWithProgress("Y:\TEST\SysDat", "Y:\TEST\SysDat " & @Year & " - " & @Min)
                    CopyWithProgress("Z:\TEST\SysDat", "Y:\TEST\SysDat")

            EndIfFunc

This is the funciton FileCompare (thanks to Ian Maxwell code from autoit) to compare the files

; #FUNCTION# ====================================================================================================================
; Name ..........: _FileCompare
; Description ...: Checks the date between two files.
; Syntax ........: _FileCompare($sSource, $sDestination[, $iMethod = 0])
; Parameters ....: $sSource             - A valid file path.
;                  $sDestination        - A valid file path.
;                  $iMethod             - [optional] The timestamp to check, 0 = Modified, 1 = Created or 2 = Accessed. Default is 0.
; Return values .: Success - -1 (File 1 is earlier = OLDER than File 2.)
;                  0 (File 1 is equal to File 2.)
;                  1 (File 1 is later = NEWER than File 2.)
; Remarks .......: Date.au3 should be included.
; ===============================================================================================================================
Func _FileCompare($sSource, $sDestination, $iMethod = 0)
    Local $iDate1 = StringRegExpReplace(FileGetTime($sSource, $iMethod, 1), '(d{4})(d{2})(d{2})(d{2})(d{2})(d{2})', '1/2/3 4:5:6')
    Local $iDate2 = StringRegExpReplace(FileGetTime($sDestination, $iMethod, 1), '(d{4})(d{2})(d{2})(d{2})(d{2})(d{2})', '1/2/3 4:5:6')
    Local $iDateDiff = _DateDiff('s', $iDate2, $iDate1)
    If $iDateDiff > 0 Then Return -1
    If $iDateDiff = 0 Then Return 0
    Return 1
EndFunc   ;==>_FileCompare
Edited by swstrau118
Link to comment
Share on other sites

  • 6 months later...

Hello,

I would like to use dircopy in a script to copy a folder including all files and subfolders to another location, thereby only overwriting older files (to keep copying times to a minimum).

(The source and target folders are read rom an .ini file)

Could anyone please help me out how to get the done?

Many thanks in advance!

Link to comment
Share on other sites

  • Moderators

Zest, why would you resurrect someone else's post instead of creating one of your own, with a detailed description of both what you're trying to accomplish and what you have already tried on your own? I guarantee that you will get a much faster response by creating a new topic, rather than hijacking someone else's

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Sorry, I didn't mean to hijack anyone's post, just thought the issue was related becasue I wanted to do this myself by comparing each file and dir, which is probably necessary to get what I want (?).

Anyway, I'll start a new thread with my specific question.

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