How to move indexed files say file_1, file_2, file_3 to indexed folder_1, folder_2, folder 3. I am using for loop to create these folders and files in an indexed and automatic manner.....but how to move these files into these folders...Plz help

조회 수: 3 (최근 30일)
FileBaseName='MyDataFile_' %set file base name Mydatafile
FolderBaseName='Case_' %set folder base name case_
parameter=[1 12] %using these array values, CONTENT of each CASE file is written
for i=1:length(parameter)
filename=[FileBaseName,num2str(i)] %indexed filenames
folderName=[FolderBaseName,num2str(i)] %indexed foldernames
mkdir([FolderBaseName,num2str(i)]) % make folder first
fileID = fopen(filename,'w'); %open file for writing
THC=parameter(i) %choose parameter value for writing
fprintf(fileID, 'chosen value is %2.2f', THC); %write the content to file
fclose(fileID) %close the file
% for j=1:1:length(parameter)
% move CASE1 TO FOLDER1 (BUT HOW ??)
%I TRIED USING MOVEFILE but its not working
%END
end

채택된 답변

Matt J
Matt J 2019년 12월 8일
>> Files="file_"+(1:5)
Files =
1×5 string array
"file_1" "file_2" "file_3" "file_4" "file_5"
>> Folders="folder_"+(1:5)
Folders =
1×5 string array
"folder_1" "folder_2" "folder_3" "folder_4" "folder_5"
>> for i=1:5, movefile(Files{i},Folders{i}); end
  댓글 수: 1
shadman khan
shadman khan 2019년 12월 8일
편집: shadman khan 2019년 12월 8일
%your code works now......i edited this post and updated it before you noticed ...here's the %working example of it
%hope it helps others
%and accepting your solution...and mighty appreciate your help
parameter=[1 12 14 15 18]
for i=1:length(parameter)
Files = ['file_' sprintf('%d',i) '];
Folders = ['folder_' sprintf('%d',i)];
mkdir(Folders)
fileID = fopen(Files,'w');
THC=parameter(i)
fprintf(fileID, 'the chosen value is %2.2f', THC);
fclose(fileID)
end
% this makes five files and folders exactly in the name format as in your code
Files="file_"+(1:5)
Folders="folder_"+(1:5)
for i=1:5
movefile(Files{i},Folders{i});
end

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

추가 답변 (1개)

shadman khan
shadman khan 2019년 12월 8일
Now that i have create separate cases in separate folders
How can i copy or create a unique "folder" say "PostPorocessingResults" inside each case folder?
please help in this regard
  댓글 수: 1
shadman khan
shadman khan 2019년 12월 8일
Well never mind, i just ocmpleted this also by creating separate folders of postprocessing and moving them into it using the same technique

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

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by