Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Open a new folder

Subject: Open a new folder

From: Bruce Heu

Date: 6 Apr, 2008 21:02:01

Message: 1 of 4

Thanks for your attention:

My question is:

1, How to open a new foloder under current/or some
particular drectory by matlab and save some file in it?
The folder's name is defined using
foldername = sprintf--- based on current
parameters/variables.

2. I can open a file at current directory using
fopen('xxx.txt', 'wt');
But it fails when I tries to open a file in a folder "A"
under current directory using
fopen('\A\xxx.txt', 'wt');
How to accomplish this.

-I know it can be done by making the directory full using
fopen('C:\A\xxx.txt', 'wt'); while this make it difficult
to us when you move the file into a new folder with
different directory.

Thanks a lot.

Subject: Open a new folder

From: Yuri Geshelin

Date: 6 Apr, 2008 21:33:01

Message: 2 of 4

See help mkdir

"Bruce Heu" <yuanxin1999@hotmail.com> wrote in message
<ftbdo9$e1i$1@fred.mathworks.com>...
> Thanks for your attention:
>
> My question is:
>
> 1, How to open a new foloder under current/or some
> particular drectory by matlab and save some file in it?
> The folder's name is defined using
> foldername = sprintf--- based on current
> parameters/variables.
>
> 2. I can open a file at current directory using
> fopen('xxx.txt', 'wt');
> But it fails when I tries to open a file in a folder "A"
> under current directory using
> fopen('\A\xxx.txt', 'wt');
> How to accomplish this.
>
> -I know it can be done by making the directory full using
> fopen('C:\A\xxx.txt', 'wt'); while this make it difficult
> to us when you move the file into a new folder with
> different directory.
>
> Thanks a lot.

Subject: Open a new folder

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 6 Apr, 2008 21:45:54

Message: 3 of 4

In article <ftbdo9$e1i$1@fred.mathworks.com>,
Bruce Heu <yuanxin1999@hotmail.com> wrote:

>1, How to open a new foloder under current/or some
>particular drectory by matlab and save some file in it?
>The folder's name is defined using
>foldername = sprintf--- based on current
>parameters/variables.

mkdir(foldername);

>2. I can open a file at current directory using
>fopen('xxx.txt', 'wt');
>But it fails when I tries to open a file in a folder "A"
>under current directory using
>fopen('\A\xxx.txt', 'wt');
>How to accomplish this.

fopen('A\xxx.txt', 'wt');
--
  "I want to be remembered as the guy who gave his all whenever
  he was on the field." -- Walter Payton

Subject: Open a new folder

From: Steven Lord

Date: 7 Apr, 2008 01:57:50

Message: 4 of 4


"Bruce Heu" <yuanxin1999@hotmail.com> wrote in message
news:ftbdo9$e1i$1@fred.mathworks.com...
> Thanks for your attention:
>
> My question is:
>
> 1, How to open a new foloder under current/or some
> particular drectory by matlab and save some file in it?
> The folder's name is defined using
> foldername = sprintf--- based on current
> parameters/variables.

As others have mentioned, use MKDIR.

> 2. I can open a file at current directory using
> fopen('xxx.txt', 'wt');
> But it fails when I tries to open a file in a folder "A"
> under current directory using
> fopen('\A\xxx.txt', 'wt');
> How to accomplish this.
>
> -I know it can be done by making the directory full using
> fopen('C:\A\xxx.txt', 'wt'); while this make it difficult
> to us when you move the file into a new folder with
> different directory.

Use the FULLFILE function to combine the current directory name (which you
can obtain using the PWD function) and the subdirectory name. If your code
needs to be cross-platform, you may also want to use the FILESEP function to
construct your subdirectory name.

--
Steve Lord
slord@mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us