0

I am trying to create a MATLAB loop where I can copy all the files listed in a txt file sent to me by a colleague from one directory on my computer to another.

The code I am using is:

FileList=textread('C:\Users\Desktop\list.txt','%s')

%copy files in list from one folder to another
cd ('C:\Users\source_directory')

for n=1:numel(FileList)
source=FileList(n)
destination='C:\Users\destination_directory'
copyfile(source,destination)
end

I keep getting this error: "Error using copyfile Argument must contain a string."

My FileList is a cell character array, but I also cannot convert to a string. When I try I get this:

string(FileList) Warning: string is obsolete and will be discontinued. Use char instead. Error using string Conversion to char from cell is not possible.

Please help! Thank you.

sjb
  • 1
  • 1
  • You need to use curly braces to get the character array from the cell array: `source = FileList{n}` – gnovice May 01 '17 at 20:45
  • I've flagged an appropriate duplicate. The problem you are experiencing is that you are not accessing the cell array correctly as noted by gnovice. You use parentheses (i.e. `()`) to **slice** into a cell array. The output would be another cell array. To access the raw contents, you must use curly braces (i.e. `{}`). – rayryeng May 01 '17 at 21:00
  • THANK YOU SO MUCH! It worked! – sjb May 01 '17 at 21:05

0 Answers0