Jump to content

Strange DirCopy issue - Works in all instances except one


Recommended Posts

Hi guys,

I'm new to AutoIt (and scripting..), but I've made a few successful scripts. I'm now writing a script that will copy user files for a particular program from the Windows 7/Vista VirtualStore back to the normal file locations. (It's an older application that saves user files in Program Files and settings in HKLM.) The script is working great except for one of my DirCopy operations. It's a fairly large directory. (1.2GB total) Could that have something to do with it? Another thing I noticed in reading the DirCopy help files; It says that you shouldn't have the trailing backslash on the source and destination directories. However, I've noticed that with my other DirCopy operations in the same script, that doesn't seem to matter either way. I've tried with and without the backslash and all work except for this one. Any thoughts on what might cause it?

Here is the piece that's the problem. I put a bigger chunk in the code box so you can see it in context.

$VEST = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & $ICEUSER, "EstimateFilePath")

;$VEST = StringTrimRight ($VEST, 1)

msgbox (0, "TEST", $VEST) ;PRODUCES "C:\Program Files\MC² Software\estfiles\" --ALSO TRIED StringTrimRight to remove backslash. Same result.

If $VEST <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "EstimateFilePath", "REG_SZ", $VEST)

If StringInStr($VEST, "C:\Program Files") <> 0 Then

$VESTPF = StringReplace ($VEST, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")

Msgbox (0, "TEST", $VESTPF) ;PRODUCES "C:\DevTester\AppData\Local\VirtualStore\Program Files\MC² Software\estfiles\"

DirCopy ($VEST, @desktopdir & "\" & "OLD MC2 FILES\Estfiles\",1) ;THIS ONE DOESN'T WORK

DirCopy ($VESTPF, $VEST,1) ;THIS ONE DOESN'T WORK

If StringInStr($USERPATH, @UserName) Then ;SID DEFINED IN PREVIOUS LINES
$VRPT = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\", "ICEReportFilePath")
If $VRPT <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ICEReportFilePath", "REG_SZ", $VRPT)
If StringInStr($VRPT, "C:\Program Files") <> 0 Then
  $VRPTPF = StringReplace ($VRPT, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  Filecopy ($VRPT & "*.dat", @desktopdir & "\" & "OLD MC2 FILES\MC2Reports\",9);Copy MC2 Report Files and EDF Views in Program Files to desktop.
  FileCopy ($VRPTPF & "*.dat", $VRPT,1);Copy MC2 Report Files and EDF Views from VirtualStore to Program Files location overwriting existing files.
EndIf
$VCRW = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\", "ReportFilePath")
If $VCRW <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ReportFilePath", "REG_SZ", $VCRW)
If StringInStr($VCRW, "C:\Program Files") <> 0 Then
  $VCRWPF = StringReplace ($VCRW, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  DirCopy ($VCRW, @desktopdir & "\" & "OLD MC2 FILES\CRWReports\",1)
  DirCopy ($VCRWPF, $VCRW,1)
EndIf
$VDATA = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & $ICEUSER, "DataFilePath")
;$VDATA = StringTrimRight ($VDATA, 1)
msgbox (0, "TEST", $VDATA) ;PRODUCES "C:\Program Files\MC² Software\DatafilesTEST\" --WITH TRAILING BACKSLASH WORKS FINE
If $VDATA <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "DataFilePath", "REG_SZ", $VDATA)
If StringInStr($VDATA, "C:\Program Files") <> 0 Then
  $VDATAPF = StringReplace ($VDATA, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  MsgBox(0, "TEST", $VDATAPF) ;PRODUCES "C:\DevTester\AppData\Local\VirtualStore\Program Files\MC² Software\DatafilesTEST\" --WITH TRAILING BACKSLASH WORKS FINE
  DirCopy ($VDATA, @desktopdir & "\" & "OLD MC2 FILES\Datafiles\",1) ;NO ISSUES
  DirCopy ($VDATAPF, $VDATA,1) ;NO ISSUES
EndIf
$VEST = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & $ICEUSER, "EstimateFilePath")
;$VEST = StringTrimRight ($VEST, 1)
msgbox (0, "TEST", $VEST) ;PRODUCES "C:\Program Files\MC² Software\estfiles\"  --ALSO TRIED StringTrimRight to remove backslash.  Same result.
If $VEST <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "EstimateFilePath", "REG_SZ", $VEST)
If StringInStr($VEST, "C:\Program Files") <> 0 Then
  $VESTPF = StringReplace ($VEST, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  Msgbox (0, "TEST", $VESTPF) ;PRODUCES "C:\DevTester\AppData\Local\VirtualStore\Program Files\MC² Software\estfiles\"
  DirCopy ($VEST, @desktopdir & "\" & "OLD MC2 FILES\Estfiles\",1) ;THIS ONE DOESN'T WORK
  DirCopy ($VESTPF, $VEST,1) ;THIS ONE DOESN'T WORK
$hSearch = FileFindFirstFile ($VESTPF & "*.*") ;Get search Handle
While 1
    $sFile = FileFindNextFile ($hSearch) ;Get file name
    If @error Then ExitLoop
    If Not FileExists ($VEST & $sFile) Then
        MsgBox (16, "Error", "The file " & $sFile & " was not copied.") ;Test if file is there
    EndIf
WEnd
FileClose ($hSearch)
EndIf
$VMC2SERVERIP = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ServerConfig\", "ServerName")
$VMC2SERVERPORT = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ServerConfig\", "ServerPort")
If $VMC2SERVERIP <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ServerConfig\", "ServerName", "REG_SZ", $VMC2SERVERIP)
If $VMC2SERVERPORT <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ServerConfig\", "ServerPort", "REG_SZ", $VMC2SERVERPORT)
EndIf
wend
Link to comment
Share on other sites

Are you sure $Vest doesn't produce something like: "C:\Program Files\MC² Software\estfiles\ " <- Notice the space after the backslash

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

I guess there's a character limit in the code window? Same thing happened to me last time. It cuts off the code.

If StringInStr($USERPATH, @UserName) Then ;SID DEFINED IN PREVIOUS LINES

$VRPT = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\", "ICEReportFilePath")

If $VRPT <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ICEReportFilePath", "REG_SZ", $VRPT)

If StringInStr($VRPT, "C:\Program Files") <> 0 Then

$VRPTPF = StringReplace ($VRPT, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")

Filecopy ($VRPT & "*.dat", @desktopdir & "\" & "OLD MC2 FILES\MC2Reports\",9);Copy MC2 Report Files and EDF Views in Program Files to desktop.

FileCopy ($VRPTPF & "*.dat", $VRPT,1);Copy MC2 Report Files and EDF Views from VirtualStore to Program Files location overwriting existing files.

EndIf

$VCRW = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\", "ReportFilePath")

If $VCRW <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ReportFilePath", "REG_SZ", $VCRW)

If StringInStr($VCRW, "C:\Program Files") <> 0 Then

$VCRWPF = StringReplace ($VCRW, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")

DirCopy ($VCRW, @desktopdir & "\" & "OLD MC2 FILES\CRWReports\",1)

DirCopy ($VCRWPF, $VCRW,1)

EndIf

$VDATA = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & $ICEUSER, "DataFilePath")

;$VDATA = StringTrimRight ($VDATA, 1)

msgbox (0, "TEST", $VDATA) ;PRODUCES "C:\Program Files\MC² Software\DatafilesTEST\" --WITH TRAILING BACKSLASH WORKS FINE

If $VDATA <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "DataFilePath", "REG_SZ", $VDATA)

If StringInStr($VDATA, "C:\Program Files") <> 0 Then

$VDATAPF = StringReplace ($VDATA, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")

MsgBox(0, "TEST", $VDATAPF) ;PRODUCES "C:\DevTester\AppData\Local\VirtualStore\Program Files\MC² Software\DatafilesTEST\" --WITH TRAILING BACKSLASH WORKS FINE

DirCopy ($VDATA, @desktopdir & "\" & "OLD MC2 FILES\Datafiles\",1) ;NO ISSUES

DirCopy ($VDATAPF, $VDATA,1) ;NO ISSUES

EndIf

$VEST = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & $ICEUSER, "EstimateFilePath")

;$VEST = StringTrimRight ($VEST, 1)

msgbox (0, "TEST", $VEST) ;PRODUCES "C:\Program Files\MC² Software\estfiles\" --ALSO TRIED StringTrimRight to remove backslash. Same result.

If $VEST <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "EstimateFilePath", "REG_SZ", $VEST)

If StringInStr($VEST, "C:\Program Files") <> 0 Then

$VESTPF = StringReplace ($VEST, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")

Msgbox (0, "TEST", $VESTPF) ;PRODUCES "C:\DevTester\AppData\Local\VirtualStore\Program Files\MC² Software\estfiles\"

DirCopy ($VEST, @desktopdir & "\" & "OLD MC2 FILES\Estfiles\",1) ;THIS ONE DOESN'T WORK

DirCopy ($VESTPF, $VEST,1) ;THIS ONE DOESN'T WORK

$hSearch = FileFindFirstFile ($VESTPF & "*.*") ;Get search Handle

While 1

$sFile = FileFindNextFile ($hSearch) ;Get file name

If @error Then ExitLoop

If Not FileExists ($VEST & $sFile) Then

MsgBox (16, "Error", "The file " & $sFile & " was not copied.") ;Test if file is there

EndIf

WEnd

FileClose ($hSearch)

EndIf

$VMC2SERVERIP = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ServerConfig\", "ServerName")

$VMC2SERVERPORT = RegRead ("HKU\" & $SID & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ServerConfig\", "ServerPort")

If $VMC2SERVERIP <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ServerConfig\", "ServerName", "REG_SZ", $VMC2SERVERIP)

If $VMC2SERVERPORT <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ServerConfig\", "ServerPort", "REG_SZ", $VMC2SERVERPORT)

EndIf

wend

MsgBox (0, "ICE UAC File Transfer Tool", "Please check your desktop for a 'OLD MC2 FILES' folder. This folder contains a backup of user files found in your MC² Software folder. Some of these files may have been replaced by files found in the Windows VirtualStore. Please verify that the estimates, reports, and knowledge base files in ICE are current before deleting the 'OLD MC2 FILES' folder.")

Exit

Link to comment
Share on other sites

Are you sure $Vest doesn't produce something like: "C:\Program Files\MC² Software\estfiles\ " <- Notice the space after the backslash

I tried a StringTrimRight (to remove the backslash when testing) and it removed the backslash. If there was a space, wouldn't the StringTrimRight get rid of the space instead?

Link to comment
Share on other sites

Are you sure $Vest doesn't produce something like: "C:\Program Files\MC² Software\estfiles\ " <- Notice the space after the backslash

I just went to the registry key $VEST is reading and added a space to the end of it. StringTrimRight removes the space and leaves the backslash.

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