cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
kabbin
Level 2

Getting CopyFile() function to actually copy

Hi -
I'm a newbie to IS 2010. I'm trying to copy a file using a CA in a Basic MSI project, however I'm not able to get it work. The file to be copied exists. Below is the snippet....

#define SRC_DIR "C:\\MVLK"

function Fn_CmnAppDataDir(hMSI)
BOOL bRESULT;

begin

if (ExistsDir ("CommonAppDataFolder\\MVLK\\data") != EXISTS) then

MessageBox ("Folder " + CommonAppDataFolder + "\\MVLK\\data does not exist.", INFORMATION);

bRESULT = CopyFile(SRC_DIR ^ "conf.txt", CommonAppDataFolder\\MVLK\\data ^ "conf.txt");
if (bRESULT) then
MessageBox ("File copied successfully", INFORMATION);
else
MessageBox ("Unable to copy file", WARNING);
endif;

endif;
end


The condition checks seem to be happening fine since it throws the "folder does not exist" and the "unable to copy" msgs. Also I've set this CA for Immediate Execution and to occur after InstallFinalize in the exec sequence. What am I doing wrong? Any help is appreciated.

Thanks,
SK
Labels (1)
0 Kudos
(1) Reply
Dan_Galender
Level 10

Your use of CommonAppDataFolder is inconsistent. Inside a quoted string, its value is just the string "CommonAppDataFolder", while used just by itself, its value is the corresponding folder name on the users' systems.

You've got it right in your MessageBox, but not in the other two places.

Try:

#define SRC_DIR "C:\\MVLK"

function Fn_CmnAppDataDir(hMSI)
BOOL bRESULT;

begin

if (ExistsDir (CommonAppDataFolder ^ "MVLK\\data") != EXISTS) then

MessageBox ("Folder " + CommonAppDataFolder + "\\MVLK\\data does not exist.", INFORMATION);

bRESULT = CopyFile(SRC_DIR ^ "conf.txt", CommonAppDataFolder ^ "MVLK\\data\\conf.txt");
if (bRESULT) then
MessageBox ("File copied successfully", INFORMATION);
else
MessageBox ("Unable to copy file", WARNING);
endif;

endif;
end;
0 Kudos