Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

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

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics