How to save input main folder name as the output filename
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a main folder, and inside many sub folders. Each sub-folder contains text files. I want to read the text file, and save required data. Now, I merge all subfolders in to one main folder, and running my program, and save data. I am manually modifying the output file name each time when I run different main foldres (each main folder corresponding to different doposition tools. But, now I wish to just give the main folder location, and want to save put file name as the input main folder name. My main folder name(s) are like tool1, tool2 etc. My out files are "score_tool1.csv", "parameter_tool1.csv"
my code is below:
clc;
clear all;
clc
tic
FileList=dir('D:\Mekala_Backupdata\Matlab2010\Filesfolder\PartofTextFilesData/');
j=1;
for i=3:1:(size(FileList)) %%read all files from folder of specified dir
FileName{j}=FileList(i).name;
j=j+1;
end
for j=1:size(FileName,2)
fid=fopen(['D:\Mekala_Backupdata\Matlab2010\Filesfolder\PartofTextFilesData/',FileName{j}],'r'); %%opening each files and read each line
allText = textscan(fid,'%s','delimiter','\n');
numberOfLines = length(allText{1});
allText=allText{:};
for k=1:size(allText,1)
idx_RainFallID=find(~cellfun(@isempty,regexpi(allText,'RainFallID')));
idx_LMDName=find(~cellfun(@isempty,regexpi(allText,'LMD Name')));
idx_10Under1=find(~cellfun(@isempty,regexpi(allText,'10 Under Pipe 1.Response Value')));
idx_RainFallIDtemp=allText(idx_RainFallID);
idx_RainFallIDtemp2=regexp(idx_RainFallIDtemp,' +','split');
b(j,1)=str2double(idx_RainFallIDtemp2{1}{1,3});
Variable{1,1}=char(idx_RainFallIDtemp2{1}{1,1});
end
fclose(fid)
end
xlswrite('score_tool1.csv',b)
xlswrite('parameter_tool1.csv',Variable)
0 commentaires
Réponses (1)
Geoff Hayes
le 29 Jan 2016
Kanakaiah - if your (sub?) folder is named as
folder = 'tool1';
and you want to incorporate into the filename, then you could try
scoreFilename = ['score_' folder '.csv'];
paramFilename = ['parameter_' folder '.csv'];
xlswrite(scoreFilename,b)
xlswrite(paramFilename,Variable)
2 commentaires
Geoff Hayes
le 31 Jan 2016
Kanakaiah - in your above code, where do you specify the main folder, the sub-folder, and the sub-sub-folders?
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!