How to copy a video file from an external drive to the current workspace?

3 visualizzazioni (ultimi 30 giorni)
I am working on a script which will loop through a group of large videos that I have on an external drive. In psuedo codo I want to:
loop for all files
copy video to current workspace (to increase reading speed)
open video visually
mark certian frame and time stamps
close video & delete local copy
end loop
I have most of this working except I cannot get the copyfile function to work for me, here is what I have written -- any help would be great
[file,path] = uigetfile('*.avi');
name = join([path,file]); % This is a char
CurrentDirectory = 'C:\Users\username\Desktop\Currently Working On'; % this is a char
copyfile name CurrentDirectory;
%% -- ERROR MESSAGE -- %%
% Error using copyfile
% No matching files named 'C:\Users\username\Desktop\Currently Working On\name' were
% found.

Risposta accettata

Jayant
Jayant il 27 Giu 2023
What I think is the issue you're experiencing is due to passing the variable "name" as a literal string instead of its value. To fix this, you need to concatenate the value of name with the destination directory. Here's the corrected code:
[file, path] = uigetfile('*.avi');
name = fullfile(path, file); % Create the full file path
CurrentDirectory = 'C:\Users\username\Desktop\Currently Working On';
copyfile(name, CurrentDirectory);
By using the "fullfile" function, you ensure that the file path is constructed correctly, taking into account the operating system's file separator. Then, you pass the "name" variable (which holds the full file path) and the destination directory to the "copyfile" function. You may refer to this fullfile & copyfile documentation.

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by