Is there a way to copy files with a name specified by a link contained within an array to a new folder?
8 次查看(过去 30 天)
显示 更早的评论
I am new to MatLab and am trying to copy multiple files from one folder, which the link is defined in a csv table, to a new location. I tried useing the following but it didnt work. ANy help would be much appreciated.
clear
close all
clc
%%
% Data import
Data = readtable('C:\Users\data.csv')
%%
% Select column with the file names
File_location = Data{:,5}
%%
mkdir C:\Users\Desktop\copied
status = copyfile(File_location, 'C:\Users\Desktop')
0 个评论
采纳的回答
Geoff Hayes
2020-1-30
Jack - without seeing the error message from your above code, I suspect that File_location is a cell array of paths to files and you are trying to use copyfile which copies a single file or folder from one location to another. I think that you will want to loop over every file (string) in File_location and call copyfile on that file.
5 个评论
Geoff Hayes
2020-1-31
The error message is a type in my code (in the fprintf) where it is trying to reference a variable (fileAnPath) that doesn't exist. Try changing it to
for k = 1:length(File_location)
fileAndPath = File_location{k};
status = copyfile(fileAndPath, 'C:\Users\Desktop');
fprintf('Copying file %s with status %d', fileAndPath, status);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!