Move-File: Can't move certain Files to another Folder!

조회 수: 9 (최근 30일)
Malte Räuchle
Malte Räuchle 2020년 7월 6일
댓글: Malte Räuchle 2020년 7월 7일
Hello! I want to extract some Files based on a certain criteria (here: bytes < 70 000 000). But I don't get it to work, some Ideas?
This is my approach so far..
files_zum_Testen = dir('...\MOVE_MDF\*.mf4');
move_bedingung = [files_zum_Testen.bytes] < 70000000;
move_list = fullfile({files_zum_Testen(move_bedingung).folder}, {files_zum_Testen(move_bedingung).name});
movefile (move_list, newFolder)
  댓글 수: 1
Stephen23
Stephen23 2020년 7월 6일
You will need to use a loop, and move each file separately.
The movefile documentation describes its source input as one character vector or string scalar, It does not state that the source can be a cell array of character vectors or a non-scalar string.
It states that multiple files can be matched using the wildcard *. But because you want to match on some other property (not using a wildcard) you will have to call movefile for each file.

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 7월 6일
Malte - you haven't posted the error message or describe fully what you mean by I don't get it to work. According to movefile input arguments, the source is a character vector corresponding to a single file or directory. I don't think that passing in a cell array (list of files) will work and so you will need to move each file individually.
  댓글 수: 7
Stephen23
Stephen23 2020년 7월 7일
편집: Stephen23 2020년 7월 7일
"And I have no explanation for it.."
Your approach means that when the logical scalar fileToMove is false then you are generating comma-separated lists with zero outputs, and so fullfile has zero input arguments. That causes the error. While you could make this approach work (e.g. use if and you need to use index k rather than a logical scalar to select from files_zum_Testen) it would likely be simpler and clearer to use the logical array to filter the required files before the loop, e.g.:
D = '...\MOVE_MDF';
S = dir(fullfile(D,'*.mf4'));
X = [S.bytes] < 70000000;
C = {S(X).name}; % filter here!
for k = 1:numel(C)
F = fullfile(D,C{k});
movefile(F, newFolder)
end
Malte Räuchle
Malte Räuchle 2020년 7월 7일
Thank you all for your help. I'm new to matlab and still learning.. A combination of both answers was a good solution and exactly what I needed!!
Appreciate it!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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