Sign in to follow this  
Followers 0
bobbykohn

Noob question: Folder copy then compare

15 posts in this topic

I've wrote my first very simple program below, but for whatever reason I can't get the Final If statement (commented out) to work using the variables I set. I must be missing something very simple, but I figured someone could look at it very briefly and let me know. Thanks!!!

$sizeCIS = DirGetSize("C:\Users\CIS", 0)

$sizeDefault = DirGetSize("C:\Users\Default", 0)

RunWait("cacls C:\Users\CIS /t /e /g Administrators:F")

RunWait("cacls C:\Users\Default /t /e /g Administrators:F")

If FileExists("C:\Users\Default") Then

DirRemove("C:\Users\Default", 1)

Sleep(500)

DirCreate("C:\Users\Default")

Sleep(500)

DirCopy("C:\Users\CIS", "C:\Users\Default", 1)

EndIf

MsgBox(0, "Done", "Size(bytes):" & $sizeCIS & @CRLF & "Size(bytes):" & $sizeDefault)

;If $sizeCIS == $sizeDefault Then

; MsgBox(0, "Copy Completed", "CIS profile has copied successfully.")

; ElseIf MsgBox(0, "Copy Failed", "Please check folders as the copy process failed.") Then

;EndIf

Share this post


Link to post
Share on other sites



I have heard that you should only use == comparing characters of a string. Is your comparison a string or numeric?, it looks like it might be numeric. I came to autoit from C++ myself so it is natural for me to use ==, but just one = is all it takes for comparison here and I have heard double = can cause problems. I'll start debugging your code on my end now.


I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Oh geez, dirgetsize() returns an array use:

If $sizeCIS[0] = $sizeDefault[0] Then

Put your mouse over the DirGetSize function label in SciTE and press F1 or lookup "autoit dirgetsize" manually with the google.

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

Thanks, but when I use the array [0] it gives "Error subscript used with non-Array variable." I tried that before and I've read on the function, but can't find what I'm doing wrong. I don't have a programming background (obviously), but would like something like this just to do a repeated task at work. Thanks for the input!...Not sure what's going on still though.

Share this post


Link to post
Share on other sites

Also the variables are setting the correct numeric values that I am looking for so they're equal. I used = and == hoping that it was the issue, but neither seem to make a difference. Thanks

Share this post


Link to post
Share on other sites

I'm sorry for not being thorough, in fact I skimmed too fast, your not using the parameter for the array so no array is returned. I apologize for my sloppy misguided response. What do you want the program to do? I have never used cacls before.


I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Try changing your block IF structure to look like this:

If $sizeCIS == $sizeDefault Then
     MsgBox(0, "Copy Completed", "CIS profile has copied successfully.")
Else
     MsgBox(0, "Copy Failed", "Please check folders as the copy process failed.") 
EndIf

Your previous Else was stated as an elseif but there was no condition to the elseif so I figure it's just an else :)

I'm pretty sure that is your solution and or bug.

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

No problem. I appreciate any input. I basically just want to copy a directory (our "CIS" profile in Windows7) and replace the "Default" profile. I found that this was easy enough to do and ran the program on a couple hundred computers, but I found a couple rare instances where the administrator didn't have permissions to some of the files in the "CIS" profile. Therefore the program would fail without warning, because I didn't have any error checking in it. The cacls is a command prompt command to give permissions of folders/files to users (in this case full rights to an administrator). Thanks again!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I will find a use for cacls; a nice tool to have around. Thank you for the upgrade. I left a Then statement previously in my solution above. It was an error and has been removed.

The correct IF block structure is here:

If $sizeCIS == $sizeDefault Then
     MsgBox(0, "Copy Completed", "CIS profile has copied successfully.")
Else
     MsgBox(0, "Copy Failed", "Please check folders as the copy process failed.")
EndIf
Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I tried that and you're probably right that the "ElseIf" isn't correct there (I replaced it with Else and removed Then), but the program still isn't working properly as the 2 folder sizes will be different and it still says "CIS profile has copied successfully." ...I'm sure I have something with the syntax incorrect or I'm making a stupid mistake, but this is driving me slightly crazy. lol.

Edited by bobbykohn

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

This edited code works for me you can use it to help yourself test.

and by works I mean that it will report same-size or differant-size folders

good luck!

$sizeCIS = DirGetSize("C:Util", 0)
$sizeDefault = DirGetSize("C:UtilMedia Replication", 0)
;RunWait("cacls C:UsersCIS /t /e /g Administrators:F")
;RunWait("cacls C:UsersDefault /t /e /g Administrators:F")
;If FileExists("C:UsersDefault") Then
;DirRemove("C:UsersDefault", 1)
;Sleep(500)
;DirCreate("C:UsersDefault")
;Sleep(500)
;DirCopy("C:UsersCIS", "C:UsersDefault", 1)
;EndIf
;MsgBox(0, "Done", "Size(bytes):" & $sizeCIS & @CRLF & "Size(bytes):" & $sizeDefault)
out($sizeCIS)
out($sizeDefault)
If $sizeCIS == $sizeDefault Then
    MsgBox(0, "Copy Completed", "CIS profile has copied successfully.")
Else
    MsgBox(0, "Copy Failed", "Please check folders as the copy process failed.")
EndIf
func out($output= "");debug tool
    ConsoleWrite(@CRLF&$output);to console new line, value of $output
EndFunc; end out()

sorry if you saw the out("your face") it was just a debug tool. Dumb things keep me laughing inside, I didn't intend any offence.

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

Shouldn't you do the following command after you copied everything in stead of the beginning of the script when it is supposed to check the copy went correct?:

$sizeDefault = DirGetSize("C:UsersDefault", 0)

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

Awesome! Thanks Xandy and Jos...I got it working! I appreciate the help. I just moved where the variable was declared like you suggested Jos and it works perfect. Thanks Xandy I'm sure that would have worked too! I'm very happy now. lol.

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