Borrar filtros
Borrar filtros

Copying multiple files in a different location

61 visualizaciones (últimos 30 días)
GreyHunter
GreyHunter el 7 de Oct. de 2020
Comentada: GreyHunter el 8 de Oct. de 2020
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 comentarios
Walter Roberson
Walter Roberson el 7 de Oct. de 2020
Editada: Walter Roberson el 7 de Oct. de 2020
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 el 7 de Oct. de 2020
Editada: GreyHunter el 7 de Oct. de 2020
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

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 7 de Oct. de 2020
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 comentarios
Walter Roberson
Walter Roberson el 8 de Oct. de 2020
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 el 8 de Oct. de 2020
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.

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by