Jump to content
Sign in to follow this  
pdixon724

FileCopy produces a 'file' named after the destination folder

Recommended Posts

pdixon724

Hello all,

Please Note: I'm fairly new to Autoit and scripting in general. I have encountered this before with a previous script, but that solution doesn't seem to work with this script. I am copying some .dat files from a Program Files directory to a folder on the desktop before I overwrite the files in the Program Files directory with newer files. The FileCopy gives me a file named after the destination folder instead of the .dat files. I thought in my previous script that this was related to a misplaced "\" in my paths, but that doesn't seem to be the case here. I've included the problem portion and my entire script below. My variable names might be a little confusing. Be sure to differentiate "$VMC2RPTPATH" and "$VMC2RPTPFPATH". Any thoughts on what might cause it? Thanks in advance.

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

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

MsgBox (0, "test", $VMC2RPTPATH);PRODUCES "C:\Program Files (x86)\MC² Software\"

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

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

Filecopy ($VMC2RPTPATH & "*.dat", @desktopdir & "\" & "OLD MC2 FILES\MC2Reports\",1);Copy MC2 Report Files in Program Files to desktop before overwriting with VirtualStore files.

DirCopy ($VMC2RPTPFPATH, $VMC2RPTPATH,1);Copy MC2 Report Files from VirtualStore to Program Files location overwriting existing files.

EndIf

#RequireAdmin
If @OSArch = "X64" Then
Const $64MARK = "Wow6432Node\"
Const $64PFMARK = " (x86)"
Else
Const $64MARK = ""
Const $64PFMARK = ""
EndIf
;Set variables for VirtualStore MC2 program file path, normal MC2 program file path, and ask user for their ICE user login name and set it to a variable.
$VMC2PATH = "C:\Users\" & @UserName & "\" & "AppData\Local\VirtualStore\Program Files" & $64PFMARK & "\" & "MC² Software\"
$MC2PATH = RegRead ("HKLM\Software\" & $64MARK & "MC2\ICE2000", "ProgramFilePath")
$y = 1
while $y = 1
$ICEUSER = InputBox ("ICE File Transfer", "Please enter your ICE username.  That is the name displayed on the ICE login screen before opening the program.  It is not case-sensitive.")
$USERNAME = MsgBox (4, "ICE File Transfer", "Is your ICE user name correct?  " & $ICEUSER)
If $USERNAME = 6 Then ExitLoop
WEnd
;Determine Windows SID of the user that is currently logged in.
$i = 1
while 1
$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList",$i)
$i = $i+1
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $var,"ProfileImagePath")
;If SID is found, set variables for MC2 Report, Crystal Report, Datafiles, and Estfiles file paths found in VirtualStore in registry and write them to the normal MC2 registry location.  Also, set variables for MC2 Program Files Folders and copy files back to normal Program Files locations.
If StringInStr($var2, @UserName) Then
$VMC2RPTPATH = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\", "ICEReportFilePath")
If $VMC2RPTPATH <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ICEReportFilePath", "REG_SZ", $VMC2RPTPATH)
MsgBox (0, "test", $VMC2RPTPATH);PRODUCES "C:\Program Files (x86)\MC² Software\"
If StringInStr($VMC2RPTPATH, "C:\Program Files") <> 0 Then
  $VMC2RPTPFPATH = StringReplace ($VMC2RPTPATH, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  Filecopy ($VMC2RPTPATH & "*.dat", @desktopdir & "\" & "OLD MC2 FILES\MC2Reports\",1);Copy MC2 Report Files in Program Files to desktop before overwriting with VirtualStore files.
  DirCopy ($VMC2RPTPFPATH, $VMC2RPTPATH,1);Copy MC2 Report Files from VirtualStore to Program Files location overwriting existing files.
EndIf
$VCRWRPTPATH = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\", "ReportFilePath")
If StringInStr($VCRWRPTPATH, "C:\Program Files") <> 0 Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ReportFilePath", "REG_SZ", $VCRWRPTPATH)
  $VCRWRPTPFPATH = StringReplace ($VCRWRPTPATH, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  DirCopy ($VCRWRPTPATH, @desktopdir & "\" & "OLD MC2 FILES\CRWReports\",1)
  DirCopy ($VCRWRPTPFPATH, $VCRWRPTPATH,1)
EndIf
$VMC2DATAPATH = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & "\" & $ICEUSER, "DataFilePath")
If StringInStr($VMC2DATAPATH, "C:\Program Files") <> 0 Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "DataFilePath", "REG_SZ", $VMC2DATAPATH)
  $VMC2DATAPFPATH = StringReplace ($VMC2DATAPATH, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  DirCopy ($VMC2DATAPATH, @desktopdir & "\" & "OLD MC2 FILES\Datafiles\",1)
  DirCopy ($VMC2DATAPFPATH, $VMC2DATAPATH,1)
EndIf
$VMC2ESTPATH = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & "\" & $ICEUSER, "EstimateFilePath")
If StringInStr($VMC2ESTPATH, "C:\Program Files") <> 0 Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "EstimateFilePath", "REG_SZ", $VMC2ESTPATH)
  $VMC2ESTPFPATH = StringReplace ($VMC2ESTPATH, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  DirCopy ($VMC2ESTPATH, @desktopdir & "\" & "OLD MC2 FILES\Estfiles\",1)
  DirCopy ($VMC2ESTPFPATH, $VMC2ESTPATH,1)
EndIf
$VMC2SERVERIP = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ServerConfig\", "ServerName")
$VMC2SERVERPORT = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ServerConfig\", "ServerPort")
If $VMC2SERVERIP <> "" Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ServerConfig\", "ServerName", "REG_SZ", $VMC2SERVERIP)
EndIf
If $VMC2SERVERPORT <> "" Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ServerConfig\", "ServerPort", "REG_SZ", $VMC2SERVERPORT)
EndIf
EndIf
wend
MsgBox (0, "MC2 UAC 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

Share this post


Link to post
Share on other sites
pdixon724

My code didn't take for some reason. Here it is.

#RequireAdmin
If @OSArch = "X64" Then
Const $64MARK = "Wow6432Node\"
Const $64PFMARK = " (x86)"
Else
Const $64MARK = ""
Const $64PFMARK = ""
EndIf
;Set variables for VirtualStore MC2 program file path, normal MC2 program file path, and ask user for their ICE user login name and set it to a variable.
$VMC2PATH = "C:\Users\" & @UserName & "\" & "AppData\Local\VirtualStore\Program Files" & $64PFMARK & "\" & "MC² Software\"
$MC2PATH = RegRead ("HKLM\Software\" & $64MARK & "MC2\ICE2000", "ProgramFilePath")
$y = 1
while $y = 1
$ICEUSER = InputBox ("ICE File Transfer", "Please enter your ICE username.  That is the name displayed on the ICE login screen before opening the program.  It is not case-sensitive.")
$USERNAME = MsgBox (4, "ICE File Transfer", "Is your ICE user name correct?  " & $ICEUSER)
If $USERNAME = 6 Then ExitLoop
WEnd
;Determine Windows SID of the user that is currently logged in.
$i = 1
while 1
$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList",$i)
$i = $i+1
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $var,"ProfileImagePath")
;If SID is found, set variables for MC2 Report, Crystal Report, Datafiles, and Estfiles file paths found in VirtualStore in registry and write them to the normal MC2 registry location.  Also, set variables for MC2 Program Files Folders and copy files back to normal Program Files locations.
If StringInStr($var2, @UserName) Then
$VMC2RPTPATH = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\", "ICEReportFilePath")
If $VMC2RPTPATH <> "" Then RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ICEReportFilePath", "REG_SZ", $VMC2RPTPATH)
MsgBox (0, "test", $VMC2RPTPATH)
If StringInStr($VMC2RPTPATH, "C:\Program Files") <> 0 Then
  $VMC2RPTPFPATH = StringReplace ($VMC2RPTPATH, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  Filecopy ($VMC2RPTPATH & "*.dat", @desktopdir & "\" & "OLD MC2 FILES\MC2Reports\",1);Copy MC2 Report Files in Program Files to desktop.
  DirCopy ($VMC2RPTPFPATH, $VMC2RPTPATH,1);Copy MC2 Report Files from VirtualStore to Program Files location overwriting existing files.
EndIf
$VCRWRPTPATH = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\", "ReportFilePath")
If StringInStr($VCRWRPTPATH, "C:\Program Files") <> 0 Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ReportFilePath", "REG_SZ", $VCRWRPTPATH)
  $VCRWRPTPFPATH = StringReplace ($VCRWRPTPATH, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  DirCopy ($VCRWRPTPATH, @desktopdir & "\" & "OLD MC2 FILES\CRWReports\",1)
  DirCopy ($VCRWRPTPFPATH, $VCRWRPTPATH,1)
EndIf
$VMC2DATAPATH = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & "\" & $ICEUSER, "DataFilePath")
If StringInStr($VMC2DATAPATH, "C:\Program Files") <> 0 Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "DataFilePath", "REG_SZ", $VMC2DATAPATH)
  $VMC2DATAPFPATH = StringReplace ($VMC2DATAPATH, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  DirCopy ($VMC2DATAPATH, @desktopdir & "\" & "OLD MC2 FILES\Datafiles\",1)
  DirCopy ($VMC2DATAPFPATH, $VMC2DATAPATH,1)
EndIf
$VMC2ESTPATH = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ICE2000\Paths\" & "\" & $ICEUSER, "EstimateFilePath")
If StringInStr($VMC2ESTPATH, "C:\Program Files") <> 0 Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "EstimateFilePath", "REG_SZ", $VMC2ESTPATH)
  $VMC2ESTPFPATH = StringReplace ($VMC2ESTPATH, "C:\", @userprofiledir & "\" & "AppData\Local\VirtualStore\")
  DirCopy ($VMC2ESTPATH, @desktopdir & "\" & "OLD MC2 FILES\Estfiles\",1)
  DirCopy ($VMC2ESTPFPATH, $VMC2ESTPATH,1)
EndIf
$VMC2SERVERIP = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ServerConfig\", "ServerName")
$VMC2SERVERPORT = RegRead ("HKU\" & $var & "_Classes\VirtualStore\MACHINE\SOFTWARE\" & $64MARK & "MC2\ServerConfig\", "ServerPort")
If $VMC2SERVERIP <> "" Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ServerConfig\", "ServerName", "REG_SZ", $VMC2SERVERIP)
EndIf
If $VMC2SERVERPORT <> "" Then
  RegWrite ("HKLM\Software\" & $64MARK & "MC2\ServerConfig\", "ServerPort", "REG_SZ", $VMC2SERVERPORT)
EndIf
EndIf
wend
MsgBox (0, "MC2 UAC 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

Share this post


Link to post
Share on other sites
pdixon724

I guess the code is too long for the code window? Let's try outside the code window:

#RequireAdmin

If @OSArch = "X64" Then

Const $64MARK = "Wow6432Node\"

Const $64PFMARK = " (x86)"

Else

Const $64MARK = ""

Const $64PFMARK = ""

EndIf

;Set variables for VirtualStore MC2 program file path, normal MC2 program file path, and ask user for their ICE user login name and set it to a variable.

$VMC2PATH = "C:\Users\" & @UserName & "\" & "AppData\Local\VirtualStore\Program Files" & $64PFMARK & "\" & "MC² Software\"

$MC2PATH = RegRead ("HKLM\Software\" & $64MARK & "MC2\ICE2000", "ProgramFilePath")

$y = 1

while $y = 1

$ICEUSER = InputBox ("ICE File Transfer", "Please enter your ICE username. That is the name displayed on the ICE login screen before opening the program. It is not case-sensitive.")

$USERNAME = MsgBox (4, "ICE File Transfer", "Is your ICE user name correct? " & $ICEUSER)

If $USERNAME = 6 Then ExitLoop

WEnd

;Determine Windows SID of the user that is currently logged in.

$i = 1

while 1

$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList",$i)

$i = $i+1

If @error <> 0 Then ExitLoop

$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $var,"ProfileImagePath")

;If SID is found, set variables for MC2 Report, Crystal Report, Datafiles, and Estfiles file paths found in VirtualStore in registry and write them to the normal MC2 registry location. Also, set variables for MC2 Program Files Folders and copy files back to normal Program Files locations.

If StringInStr($var2, @UserName) Then

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

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

MsgBox (0, "test", $VMC2RPTPATH)

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

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

Filecopy ($VMC2RPTPATH & "*.dat", @desktopdir & "\" & "OLD MC2 FILES\MC2Reports\",1);Copy MC2 Report Files in Program Files to desktop.

DirCopy ($VMC2RPTPFPATH, $VMC2RPTPATH,1);Copy MC2 Report Files from VirtualStore to Program Files location overwriting existing files.

EndIf

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

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

RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths", "ReportFilePath", "REG_SZ", $VCRWRPTPATH)

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

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

DirCopy ($VCRWRPTPFPATH, $VCRWRPTPATH,1)

EndIf

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

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

RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "DataFilePath", "REG_SZ", $VMC2DATAPATH)

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

DirCopy ($VMC2DATAPATH, @desktopdir & "\" & "OLD MC2 FILES\Datafiles\",1)

DirCopy ($VMC2DATAPFPATH, $VMC2DATAPATH,1)

EndIf

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

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

RegWrite ("HKLM\Software\" & $64MARK & "MC2\ICE2000\Paths" & "\" & $ICEUSER, "EstimateFilePath", "REG_SZ", $VMC2ESTPATH)

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

DirCopy ($VMC2ESTPATH, @desktopdir & "\" & "OLD MC2 FILES\Estfiles\",1)

DirCopy ($VMC2ESTPFPATH, $VMC2ESTPATH,1)

EndIf

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

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

If $VMC2SERVERIP <> "" Then

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

EndIf

If $VMC2SERVERPORT <> "" Then

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

EndIf

EndIf

wend

MsgBox (0, "MC2 UAC 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

Share this post


Link to post
Share on other sites
Spiff59

The behavior you describe does sound, as you said, like a missing slash on the end of the dest path, but

looking it over, I can't see a darn thing wrong with your code.

If you convert the FileCopy() to a Msgbox() does it display 2 valid paths?

Maybe try FileCopy() with the flag parm set to 9 to confirm that the required existing destination directory is named exactly as in your script?

Maybe a third set of eyes will come up with an idea...

Edited by Spiff59

Share this post


Link to post
Share on other sites
pdixon724

Figured it out! Stupid mistake. The rest of my copy procedures were DirCopy which, by default, creates the destination directory if it doesn't exist. I was using a flag of "1" on the FileCopy telling it to overwrite existing files when I needed to use "9" to create the destination directory too. Like I said.... newbie... Thanks for the reply, Spiff.

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  

×