Why is MATLAB 7.0.4 (R14SP2) unable to recognize my files, when I use the COPYFILE command in my script?

1 view (last 30 days)
I run a script, myfile.m, which contains the following code:
FullPathTempDir = tempname;
[temp_dir temp_file] = fileparts(FullPathTempDir);
mkdir(FullPathTempDir);
destinationFile = [temp_file,'.m'];
origPath = addpath(FullPathTempDir);
copyfile('hSampleDisp.m',fullfile(FullPathTempDir,destinationFile));
type(temp_file);
I receive the following error :
??? Error using ==> type
tp103239 is a directory.
Error in ==> myfile at 7
type(temp_file);

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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.

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Products


Release

R14SP2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!