Read filenames from folder A and rename files from folder B as filenames if folder A
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I would like to rename files (more than 600) in a folder. Particularly read the file names from folder A and rename the files from folder B as folder A file-names. I tried to use movefile, but did not work.
for i = 1:Num;
% read filename from folder A
tempA = ReadHis(filesA(i).name); % read his file
fprintf(1,'File read %s\n',filesA(i).name); %Matlab read the files name wise
filenameA = filesA(i).name
% read filename from folder B (old)
tempB = ReadHis(filesB(i).name); % read his file
fprintf(1,'File read %s\n',filesB(i).name); %Matlab read the files name wise
filenameB = filesB(i).name
movefile(filenameB,filenameA);
end
??? Error using ==> movefile No matching files were found.
Any help or suggestion will be appreciable.
0 件のコメント
採用された回答
Jan
2013 年 4 月 5 日
編集済み: Jan
2013 年 4 月 5 日
movefile(source, dest) moves the file from source to dest. The error message means, that the source file is not found.
You did not show or explain it, but it seems like the structs filesA and filesB come from the dir() command. Then note, that the fields name contain the file name only, but not the absolute path with the folder name. Then the file "filesB(i).name" are searched in the currently active folder as replied by cd.
When the filesA are insider C:\Temp\FolderA and for filesB in C\Temp\FolderB, add these names to get absolute files:
pathA = 'C:\Temp\FolderA'
pathB = 'C:\Temp\FolderB'
filesA = dir(fullfile(pathA, '*.ext'));
filesB = dir(fullfile(pathB, '*.ext'));
...
movefile(fullfile(pathB, filenameB), fullfile(pathA, filenameA))
Btw, I did not understand which file should be renamed by which strategy.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Downloads についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!