Copying multiple files in a different location

60 次查看(过去 30 天)
I have a bunch of files(around 1000) with the audio signals in them and I am trying to copy-paste them in another direction ( another folder). I would like to paste them with the same names but I do not want to use the dir function. Can anyone advise what other options do I have?
Many thanks in advance.
  12 个评论
Walter Roberson
Walter Roberson 2020-10-7
编辑:Walter Roberson 2020-10-7
If they all start with a common prefix and have a common suffix then you can use copyfile with wildcards. For example,
copyfile('B*.wav', '../save_the_waves/')
Just make sure that the destination directory exists first.
GreyHunter
GreyHunter 2020-10-7
编辑:GreyHunter 2020-10-7
They do not follow specific sequence.
@Mario I am comfused how can I copy with the ls all the files and audio signals into another location

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2020-10-7
copy with the ls all the files and audio signals into another location
destination_directory = '../copy_of_files';
if ~exist(destination_directory, 'dir')
mkdir(destination_directory);
end
copyfile( '*.wav', destination_directory)
copyfile( '*.jpg', destination_directory);
  5 个评论
Walter Roberson
Walter Roberson 2020-10-8
Example1 and example2 appear to be directories (also known as folders) rather than files ??
Are you sure you are not permitted to use dir() ? When you do not know the directory and file names ahead of time, dir() is the best way to proceed. There are cases where ls can output misleading filenames.
GreyHunter
GreyHunter 2020-10-8
yes I am sure that I am not allowed to use dir.
what about if I have a text file which includes all the folder names and audio names?
I have created the below code
src = 'example';
fileFilter = '*.';
destination = 'example1';
files = ls(fullfile(src,fileFilter));
for fileIdx = 1:size(files,1)
filename = strtrim(string(files(fileIdx,:)));
srcPath = fullfile(src,filename);
destPath = fullfile(destination,filename);
copyfile(srcPath,destPath);
end
but i have an error with it:Error using copyfile
Cannot copy or move a file or directory onto itself.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by