函数addpath()赢了';不授予对子文件夹中文件的访问权限

函数addpath()赢了';不授予对子文件夹中文件的访问权限,path,subdirectory,Path,Subdirectory,我在一个子文件夹中有很多数据文件。但是当我尝试使用addpath()访问它们时,什么也没有发生。路径搜索似乎被固定在运行脚本的文件夹中 脚本保存在Y:\97 Master\RiometerData\ASCII 我要访问的数据文件存储在 Y:\97 Master\RiometerData\ASCII\S05\2011 我有多个子文件夹S01-S05,每个文件夹都包含几年的数据 我尝试了addpath('Y:\97 Master\RiometerData\ASCII\S05\2011')和addpa

我在一个子文件夹中有很多数据文件。但是当我尝试使用addpath()访问它们时,什么也没有发生。路径搜索似乎被固定在运行脚本的文件夹中

脚本保存在
Y:\97 Master\RiometerData\ASCII

我要访问的数据文件存储在
Y:\97 Master\RiometerData\ASCII\S05\2011

我有多个子文件夹S01-S05,每个文件夹都包含几年的数据

我尝试了
addpath('Y:\97 Master\RiometerData\ASCII\S05\2011')
addpath('S05\2011')
。如果我将文件移动到我的ASCII文件夹中,它就可以正常工作,但如果它存储在子文件夹中,则无法正常工作

addpath('Y:\97 Master\RiometerData\ASCII\S05\2011')
fileName = 'testFile.txt';
if isfile(fileName)
    data = load(fileName);
else
    fprintf('File %s does> not exist.\n', fileName)
end
代码运行时没有任何错误。

问题已解决! isfile()需要完整的路径。addpath()不够(必要)。为了举例说明,已将测试文件移动到
Y:\97 Master\RiometerData\ASCII\subFolder1\SubFolder2
。对于这个例子,这不是最简单的方法,但是如果有很多文件,我需要能够更改路径和文件名。对于单个文件,写以下内容就足够了:

if isfile('Y:\97 Master\RiometerData\ASCII\subFolder1\SubFolder2\testFile.txt')
   %data = load(file)

currPath = pwd;

subFolderPath = 'subFolder1\SubFolder2';
filePath = sprintf('%s%c%s%c',currPath,'\',subFolderPath,'\');
fileName = 'testFile.txt'

file = sprintf('%s%s',filePath,fileName)

if isfile(file)
    data = load(file)
else
    fprintf('File does not exist.\n')
end