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:
multiple paths for same file

Subject: multiple paths for same file

From: Schroen

Date: 20 Jul, 2010 16:38:04

Message: 1 of 8

Hoi,

I have set several breakpoints in a file. Not all of the breakpoints are visually shown by red bullets, so I call dbstatus("-completenames"). The output:

Breakpoint for E:\DirA\DirC\FileD.m>FileD.m is on line 119.
Breakpoint for E:\DirA\DirB\..\DirC\FileD.m>FileD.m is on line 116.

Meaning, for FileD.m exist two paths: the first path is the direct path, the second one contains .., which are correct but superfluous.

Problem: One of the breakpoints is ignored by the debugger. Neither can I switch it of by mouse-clicking (since the red bullet is not shown), nor can I switch it of by dbclear('FileD').

However, I can still kill all breakpoints by dbclear all.

Question: Is there another easy solution? Is there a function, to reduce the filepath to its bare minimum (meaning without dots)? Fullfile does not seem to support this.

Greetings
/Schroen

Subject: multiple paths for same file

From: us

Date: 20 Jul, 2010 18:59:06

Message: 2 of 8

"Schroen " <t.schreiter@tudelft.nl> wrote in message <i24jdc$6m6$1@fred.mathworks.com>...
> Hoi,
>
> I have set several breakpoints in a file. Not all of the breakpoints are visually shown by red bullets, so I call dbstatus("-completenames"). The output:
>
> Breakpoint for E:\DirA\DirC\FileD.m>FileD.m is on line 119.
> Breakpoint for E:\DirA\DirB\..\DirC\FileD.m>FileD.m is on line 116.
>
> Meaning, for FileD.m exist two paths: the first path is the direct path, the second one contains .., which are correct but superfluous.
>
> Problem: One of the breakpoints is ignored by the debugger. Neither can I switch it of by mouse-clicking (since the red bullet is not shown), nor can I switch it of by dbclear('FileD').
>
> However, I can still kill all breakpoints by dbclear all.
>
> Question: Is there another easy solution? Is there a function, to reduce the filepath to its bare minimum (meaning without dots)? Fullfile does not seem to support this.
>
> Greetings
> /Schroen

one of the many solutions

     mr=matlabroot;
     frel=[mr,'/toolbox/matlab/../../toolbox/matlab/ops/../ops/unique.m'];
     fabs=which(frel)
% fabs = mr\toolbox\matlab\ops\unique.m

us

Subject: multiple paths for same file

From: Jan Simon

Date: 20 Jul, 2010 23:17:05

Message: 3 of 8

Dear Schroen,

> Question: Is there another easy solution? Is there a function, to reduce the filepath to its bare minimum (meaning without dots)?

It os not easy to remove the \.. and \. from a path efficientlly. Splitting the path at the separators, deleting the "." and the removing the ".." together with their predessors is slow.
Under Windows the fast GetFullPath system call can solve this. In addition it adds the needed "\\?\" or "\\?\UNC" infront of the string if the file name exceeds MAX_PATH characters (this was e.g. 260 in WinXP).
GetFullPath converts partial paths to full qualified paths also very fast. Is somebody interested in a C-Mex to call GetFullPath on Windows?

Jan

Subject: multiple paths for same file

From: us

Date: 20 Jul, 2010 23:40:27

Message: 4 of 8

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i25apg$muk$1@fred.mathworks.com>...
> Dear Schroen,
>
> > Question: Is there another easy solution? Is there a function, to reduce the filepath to its bare minimum (meaning without dots)?
>
> It os not easy to remove the \.. and \. from a path efficientlly. Splitting the path at the separators, deleting the "." and the removing the ".." together with their predessors is slow.
> Under Windows the fast GetFullPath system call can solve this. In addition it adds the needed "\\?\" or "\\?\UNC" infront of the string if the file name exceeds MAX_PATH characters (this was e.g. 260 in WinXP).
> GetFullPath converts partial paths to full qualified paths also very fast. Is somebody interested in a C-Mex to call GetFullPath on Windows?
>
> Jan

well...
consider that these already do the job

     help which; % <- as shown in the example above
% and in recent ML versions
     fnam=System.IO.FileInfo(fnam); % <- with a slew of output infos
% plus, there's still good old slow java's file class...

us

Subject: multiple paths for same file

From: Schroen

Date: 21 Jul, 2010 06:37:03

Message: 5 of 8

Dear us and Jan,

Thank you for your answers. However I am not sure if it solves the problem, though.

I could not find the function GetFullPath (neither in Matlab nor in the system). Jan, do you have a Matlab version you can provide?

The Javacall seems a bit heavy (and slow). I have to look deep enough into it if it can solve the problem.

I analyzed the problem more: The selection of the path (whether with dots or without) depends on the current working directory. So, when I am debugging in FileD's directory, the path without the dots is chosen. In contrast, when debugging in a different directory, the path with the dots is chosen.

/Schroen

Subject: multiple paths for same file

From: Jan Simon

Date: 21 Jul, 2010 09:58:03

Message: 6 of 8

Dear Schroen,

> I could not find the function GetFullPath (neither in Matlab nor in the system). Jan, do you have a Matlab version you can provide?

I could provide a C-Mex file in the FEX.
At first I'll compare the speed with the mentioned Java methods mentioned by Us (thanks!). If it is worth, I'll publish GetFullPath.

> I analyzed the problem more: The selection of the path (whether with dots or without) depends on the current working directory.

So the best idea would be to use working directories without "\..". Opening files in the editor including "\." and "\.." might confuse further functions also. So simply avoid this.

Jan

Subject: multiple paths for same file

From: Jan Simon

Date: 21 Jul, 2010 10:17:04

Message: 7 of 8

Dear us,

> consider that these already do the job:
> help which; % <- as shown in the example above
> % and in recent ML versions
> fnam=System.IO.FileInfo(fnam); % <- with a slew of output infos
> % plus, there's still good old slow java's file class...

For a cell string with 754 M-files with already fully qualified path (so no changes are needed atr all):
  tic; for k = 1:754; name{k} = which(name{k}); end; toc
>> 0.506 sec
  tic; for k = 1:754; m = System.IO.FileInfo(name{k}); name{k} = m.FullName; end; toc
>> 1.527 sec
  tic; for k = 1:754; name{k} = GetFullPath(name{k}); end; toc
>> 0.009 sec

(Matlab 2009a, WinXP 32bit, 1.5GHz Pentium-M, MSVC 2008)
WHICH finds only existing files, while GetFullPath works with not existing files and all folders also. System.IO.FileInfo checks the existence already, what is a nice feature, but slow, if you do not need it.
Therefore I'll put it into the FEX.

Kind regards, Jan

Subject: multiple paths for same file

From: Jan Simon

Date: 21 Jul, 2010 18:50:21

Message: 8 of 8

Dear Schroen,

GetFullPath:
  http://www.mathworks.com/matlabcentral/fileexchange/28249
This cannot solve your problem directly. But you can use it to clean the path of the files you use/open/debug.

Good luck, Jan

Tags for 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