Jump to content

Noob question: Folder copy then compare


Recommended Posts

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

Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developers

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)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Incidentally calcs is a bit depreciated these days

Have a look at icalcs which is a better version to be using

http://ss64.com/nt/icacls.html

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