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

조회 수: 2 (최근 30일)
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.

채택된 답변

Jayant
Jayant 2023년 6월 27일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by