Wildcard '*' not working for "isfile" or renaming using "move file" commands.
9 次查看(过去 30 天)
显示 更早的评论
I am trying to use a for loop to rename multiple netcdf files based on the dates within their filenames ex:
my filenames are "SAMETEXTFORALL_2018MMDD_DifferentTextForAll.nc"
and I need to get them to be "nest_1_2018MMDD000000.nc"
I am trying to use a for loop such as the following for each month:
for x=0:9;
if isfile(['SAMETEXTFORALL_2018010',num2str(x),'_*.nc'])==1;
movefile(['SAMETEXTFORALL_2018010',num2str(x),'_*.nc'], ['nest_1_2018010',num2str(x),'000000.nc']);
else
continue;
end;
end;
but the isfile is returning a 0 for each despite the file existing, and when I do the movefiles individually, they create new folders with the filename, but keep the original filename the same. I think the issue lies within the '*' wildcard, because when I put in the appropriate name for individual files it works. Any help/suggestions? There are too many files to do this on a more individual basis. Thanks!
0 个评论
采纳的回答
Gatech AE
2021-6-14
I frequently need all of the FITS image files from a directory, and so I've gotten used to using the "dir" function. It seems like you could use the wildcard below. "dir" outputs a structure of various information, but we can just get names directly by dot indexing "name." Then you can parse out the MMDD and do everything at once.
filelist = {dir('SAMETEXTFORALL_2018*.nc').name};
for fn = 1:length(filelist)
name = filelist{fn};
ind = strfind(name,'2018');
MMDD = name((ind+4):(ind+7));
modName = ['nest_1_2018' MMDD '000000.nc'];
movefile(name,modName);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!