How to make a new folder within another folder?

45 views (last 30 days)
Hi, I need to make a new sub folder within a main folder. When using mkdir(newfolder, newsubfolder) where newfolder is the parent folder where I want the newsubfolder saved, I get syntax errors every time. The full code is attached below.
> In CSVtoMatLab (line 77) Error using mkdir The filename, directory name, or volume label syntax is incorrect.
Error in CSVtoMatLab (line 85) mkdir(newfolder,newsubfolder);
Thanks for any help.
if true
clear all
close all
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Asks for User Inputs %%%%%%%%%%%%%%%%%%%%%%
prompt={'Enter a value for R:','Enter a value for C:','Enter a value for beta:','Enter a value for Life Goal:','Enter a value for N:','Enter a value for m:'};
title='Resonant Dwell Calculator Inputs';
answer=inputdlg(prompt,title);
a = str2num(answer{1});
b = str2num(answer{2});
c = str2num(answer{3});
d = str2num(answer{4});
e = str2num(answer{5});
f = str2num(answer{6});
%%%%%%%%%%%%%%%%%%%%%%%%%%File Pathing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
projectdir = 'C:\Users\it58528\Documents\Dig Test'; %Start here. or name an absolute directory
newdir = 'C:\Users\it58528\Desktop\Test';
folderinfo = dir(projectdir);
folderinfo = folderinfo([folderinfo.isdir]); %select only the directories
folderinfo = folderinfo(~ismember({folderinfo.name}, {'.', '..'})); %remove directories . and ..
%%%%%%%%%%%%%%%%Reliability goals %%%%%%%%%%%%%%%%%%%%%%%%%%%%
R = a;
C = b;
beta = c;
LifeGoal = d;
N = e;
m = f;
%%%%%%%%%%%%%%%%%%Digs for Files/Reads/Saves %%%%%%%%%%%%%%%%%%%%%
for folderidx = 1 : length(folderinfo)
thisfolder = fullfile(projectdir, folderinfo(folderidx).name);
subfolderinfo = dir(thisfolder);
subfolderinfo = subfolderinfo([subfolderinfo.isdir]); %select only the directories
subfolderinfo = subfolderinfo(~ismember({subfolderinfo.name}, {'.', '..'})); %remove directories . and ..
folderidxi = folderinfo(folderidx).name;
newfolder = fullfile(newdir, folderidxi);
mkdir(newfolder);
for subfolderidx = 1 : length(subfolderinfo)
subfolderi = subfolderinfo(subfolderidx).name;
thissubfolder = fullfile(thisfolder, subfolderi);
fileinfo = dir( fullfile(thissubfolder, '*.csv') );
newsubfolder = fullfile(newdir, subfolderi);
mkdir(newfolder,newsubfolder);
for fileidx = 1 : length(fileinfo)
filenamei = fileinfo(fileidx).name;
thisfile = fullfile(thissubfolder, filenamei);
[filepath, basename, ext] = fileparts(thisfile);
data = csvread(thisfile,5,2);
PIN(fileidx).PIN = fileinfo(fileidx).name(1:17);
PIN(fileidx).loadprofile = data(1:15,:);
PIN(fileidx).hours = sum(sum(PIN(fileidx).loadprofile,1));
PIN(fileidx).loadprofilepercent = PIN(fileidx).loadprofile./PIN(fileidx).hours;
PIN(fileidx).loadpercent = data(:,2);
PIN(fileidx).RPM = data(16,:);
loadprofilecolumn = find(PIN(fileidx).RPM>Resonance);
xSpeed = PIN(fileidx).RPM(loadprofilecolumn(1)-1);
newsubfolder = fullfile(newdir, subfolderi);
mkdir(newsubfolder)
newfilename = fullfile(newsubfolder, filenamei);
save(newfilename,'PIN');
end %files within subfolder
end %subfolders within folder
  4 Comments

Sign in to comment.

Accepted Answer

Thorsten
Thorsten on 29 Oct 2015
Just use one argument:
mkdir(newsubfolder);
And in the for fileidx = 1 : length(fileinfo) loop, get rid of the lines
newsubfolder = fullfile(newdir, subfolderi);
mkdir(newsubfolder)
This has to be done just once for each subfolder, not once for each file in a subfolder.
  4 Comments
Thorsten
Thorsten on 30 Oct 2015
Must read
newsubfolder = fullfile(newfolder, subfolderi);

Sign in to comment.

More Answers (0)

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!