filesep and move contents
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have two folders. both contain some subfolders, and their subfolders also contain subfolders.
abc1 >> sdir1 >> ab1 >> file1.txt
abc1 >> sdir2 >> ab1 >> file2.txt
abc1 >> sdir3 >> ab1 >> file3.txt
|and|
xyz2 >> sdir1 >>
xyz2 >> sdir2 >>
xyz2 >> sdir3 >>
Ok, Now I want to go in abc1, into sdir1 and move everything to xyz2 into sdir1 next, change to folder abc1 into sdir2 and move everything to xyz2 into sdir2. I want to do in a for loop, and i tried something like this
cd D:\abc1\;
dir = dir;
list1 = dir(3:end);
% check whether the folder (sdir1,2..)me name exists
for i = 1:length(list1)
if (exist (fullfile 'D:','xyz2','list1(i)'))
disp 'folder exists...'
continue
else
stop
disp 'folder doesnt exist...'
end
cd (list1{i})
mv '*' (fullfile('D:','xyz2','list1(i)'));
cd ../;
end
any idea how I can do this?
0 comentarios
Respuesta aceptada
Jan
el 19 de Oct. de 2011
Using the abbreviated form of functions without using parenthesis is confusing. I strongly recommend to stay at the functional form to avoid strange pitfals:
cd D:\dir1\; ==> cd('D:\dir1\');
disp 'folder exists...' ==> disp('folder exists...')
Sometimes the almost intelligent parsing works, but as a drawback you steer into lines like this, which are deeply confused:
if (exist (fullfile 'D:','dir2','list1(i)'))
% Better:
if exist(fullfile('D:', 'dir2', list1{i}), 'file')
Do not use the names of build-in functions as names of variables:
dir = dir % *never never never*
After this the dir command cannot be used anymore.
What does the stop command do?
Please fix this and edit the original question. Then the rest can be enhanced in a further step.
0 comentarios
Más respuestas (1)
Ver también
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!