Thread Subject: How to browse directory automatically?

Subject: How to browse directory automatically?

From: Luca Zanotti Fragonara

Date: 18 Sep, 2009 10:23:23

Message: 1 of 7

Hello everybody,

I need to browse in some folder in order to "go up one level" from the Current Directory in MatLab.
If I use the command "cd", I obtain an adress like this:

C:\goofy1\goofy2\goofy3\goofy4

My m file needs to go up one level, in goofy3, and after going down again in some other folder, different from goofy4.

I want to avoid the "uigetfolder" command, but I want that my program search without user input of course.

I didn't find on the help a command which can absolve the function "go up one level".

My code is something like this:


part_path=?(cd);

new_path=[part_path,'\otherfolder\otherfolder'];

So that now in new_path I have a path which can direct me in another folder, but that is not in the cd folder.

I could type directly the new part_path, but when I work on different pc I have to type again the new part_path.

Thank you in advance,

Luca

Subject: How to browse directory automatically?

From: Rune Allnor

Date: 18 Sep, 2009 10:52:45

Message: 2 of 7

On 18 Sep, 12:23, "Luca Zanotti Fragonara" <Luca_Zano...@libero.it>
wrote:
> Hello everybody,
>
> I need to browse in some folder in order to "go up one level" from the Current Directory in MatLab.
> If I use the command "cd", I obtain an adress like this:
>
> C:\goofy1\goofy2\goofy3\goofy4
>
> My m file needs to go up one level, in goofy3, and after going down again in some other folder, different from goofy4.
>
> I want to avoid the "uigetfolder" command, but I want that my program search without user input of course.
>
> I didn't find on the help a command which can absolve the function "go up one level".

cd ..

Rune

Subject: How to browse directory automatically?

From: Luca Zanotti Fragonara

Date: 18 Sep, 2009 11:08:02

Message: 3 of 7

Rune Allnor <allnor@tele.ntnu.no> wrote in message <49968f46-5356-4ce0-ac84-d755d20c244b@a6g2000vbp.googlegroups.com>...
> On 18 Sep, 12:23, "Luca Zanotti Fragonara" <Luca_Zano...@libero.it>
> wrote:
> > Hello everybody,
> >
> > I need to browse in some folder in order to "go up one level" from the Current Directory in MatLab.
> > If I use the command "cd", I obtain an adress like this:
> >
> > C:\goofy1\goofy2\goofy3\goofy4
> >
> > My m file needs to go up one level, in goofy3, and after going down again in some other folder, different from goofy4.
> >
> > I want to avoid the "uigetfolder" command, but I want that my program search without user input of course.
> >
> > I didn't find on the help a command which can absolve the function "go up one level".
>
> cd ..
>
> Rune


No.

1) I don't need to change the current directory. My current directory have to stay the same.

2) I need to save and load files in another folder, which is NOT nested in my Current Directory. I have to go up of one level, and then go to save my files and variables in another folder, which is not cd.
Something like that:

save([part_path,'\somestuff\somestuff'],'Goofy')

The problem is that part_path is different from cd. Or, at least, is the first part of my cd:

If my cd is C:\goofy1\goofy2\goofy3, my part_path should be C:\goofy1\goofy2

I can type directly the path IF I work always on the same pc... But I don't, so, there is some way to obtain the part_path from the cd command, or something like that?

I could use the "uigetfolder" but is not very convenient.

Subject: How to browse directory automatically?

From: Sebastiaan

Date: 18 Sep, 2009 12:19:02

Message: 4 of 7

doc fileparts

Do it on pwd (current directory) and you get the parent directory path.


"Luca Zanotti Fragonara" <Luca_Zanotti@libero.it> wrote in message <h8vn2r$3um$1@fred.mathworks.com>...
> Hello everybody,
>
> I need to browse in some folder in order to "go up one level" from the Current Directory in MatLab.
> If I use the command "cd", I obtain an adress like this:
>
> C:\goofy1\goofy2\goofy3\goofy4
>
> My m file needs to go up one level, in goofy3, and after going down again in some other folder, different from goofy4.
>
> I want to avoid the "uigetfolder" command, but I want that my program search without user input of course.
>
> I didn't find on the help a command which can absolve the function "go up one level".
>
> My code is something like this:
>
>
> part_path=?(cd);
>
> new_path=[part_path,'\otherfolder\otherfolder'];
>
> So that now in new_path I have a path which can direct me in another folder, but that is not in the cd folder.
>
> I could type directly the new part_path, but when I work on different pc I have to type again the new part_path.
>
> Thank you in advance,
>
> Luca

Subject: How to browse directory automatically?

From: Rune Allnor

Date: 18 Sep, 2009 12:52:53

Message: 5 of 7

On 18 Sep, 13:08, "Luca Zanotti Fragonara" <Luca_Zano...@libero.it>
wrote:
> Rune Allnor <all...@tele.ntnu.no> wrote in message <49968f46-5356-4ce0-ac84-d755d20c2...@a6g2000vbp.googlegroups.com>...
> > On 18 Sep, 12:23, "Luca Zanotti Fragonara" <Luca_Zano...@libero.it>
> > wrote:
> > > Hello everybody,
>
> > > I need to browse in some folder in order to "go up one level" from the Current Directory in MatLab.
> > > If I use the command "cd", I obtain an adress like this:
>
> > > C:\goofy1\goofy2\goofy3\goofy4
>
> > > My m file needs to go up one level, in goofy3, and after going down again in some other folder, different from goofy4.
>
> > > I want to avoid the "uigetfolder" command, but I want that my program search without user input of course.
>
> > > I didn't find on the help a command which can absolve the function "go up one level".
>
> > cd ..
>
> > Rune
>
> No.
>
> 1) I don't need to change the current directory. My current directory have to stay the same.

Then use '..' to navigate relative to the current directory.

> 2) I need to save and load files in another folder, which is NOT nested in my Current Directory. I have to go up of one level, and then go to save my files and variables in another folder, which is not cd.
> Something like that:
>
> save([part_path,'\somestuff\somestuff'],'Goofy')

Use '..' to navigate up in the directory hierarchy.

> The problem is that part_path is different from cd. Or, at least, is the first part of my cd:
>
> If my cd is C:\goofy1\goofy2\goofy3, my part_path should be C:\goofy1\goofy2
>
> I can type directly the path IF I work always on the same pc... But I don't, so, there is some way to obtain the part_path from the cd command, or something like that?

Do you work across a network? If so, the target disk has to
be mounted/accessible from the PC where the program runs.

> I could use the "uigetfolder" but is not very convenient.

Or you could use the very convenent '..'.

Rune

Subject: How to browse directory automatically?

From: Luca Zanotti Fragonara

Date: 18 Sep, 2009 13:14:02

Message: 6 of 7


> Or you could use the very convenent '..'.
>
> Rune


I'm so sorry that I didn't get what you were meaning by cd .. !

You saved me, thank you so much!

Subject: How to browse directory automatically?

From: Jan Simon

Date: 18 Sep, 2009 13:33:03

Message: 7 of 7

Dear Luca Zanotti Fragonara!

> > > I need to browse in some folder in order to "go up one level" from the Current Directory in MatLab.
> > > My m file needs to go up one level, in goofy3, and after going down again in some other folder, different from goofy4.

> > cd ..
> > Rune
>
> No.
>
> 1) I don't need to change the current directory. My current directory have to stay the same.
> 2) I need to save and load files in another folder, which is NOT nested in my Current Directory. I have to go up of one level, and then go to save my files and variables in another folder, which is not cd.

I'm confused by your description. Anyhow, perhaps the following helps:

You are working in the directory "C:\A\B\C" and you want to save a file in the a folder C2, which is in the parent directory:
  save('C:\A\B\C\..\C2\DataFile.dat', Data)
This writes: C:\A\B\C2\DataFile.dat
If you need a folder "D", which is in the path two levels on top of CD, use:
  newPath = fullfile(cd, '..\..\D');
So you can use '\..' to go one (or more) level up and add further folders afterwards.

Good luck, Jan

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
browse folder Luca Zanotti Fragonara 18 Sep, 2009 06:24:07
cd Luca Zanotti Fragonara 18 Sep, 2009 06:24:06
rssFeed for this Thread

Contact us at files@mathworks.com