This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
This has been verified as a bug in MATLAB 7.0.4(R14SP2) in the way COPYFILE notifies MATLAB about the changes made to a destination directory.
The followings are some workarounds to resolve the issue:
1. Using an absolute path name:
Use an absolute path name as an input to functions(TYPE in this case) accessing the destination directory as follows:
FullPathTempDir = tempname;
[temp_dir temp_file] = fileparts(FullPathTempDir);
mkdir(FullPathTempDir);
destinationFile = [temp_file,'.m'];
origPath = addpath(FullPathTempDir);
copyfile('hSampleDisp.m',fullfile(FullPathTempDir,destinationFile));
type(fullfile(FullPathTempDir,destinationFile));
2. Use WHICH or EXIST on the path of the destination directory as follows:
FullPathTempDir = tempname;
[temp_dir temp_file] = fileparts(FullPathTempDir);
mkdir(FullPathTempDir);
destinationFile = [temp_file,'.m'];
origPath = addpath(FullPathTempDir);
copyfile('hSampleDisp.m',fullfile(FullPathTempDir,destinationFile));
which temp_file
type(temp_file);
3. CD to the directory, in which the file is located, before accessing the file.
Best Answer