From: Jon Harris on 23 Mar 2010 17:22 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hobb1a$7ga$1(a)fred.mathworks.com>... > > This seems to work fine with relative or absolute paths. But if the file is just a name, I get this: > > > > » file='test.txt' > > file = > > test.txt > > » fullpath=cd(cd(fileparts(file))) > > ??? Name is nonexistent or not a directory > > Easy to fix if you check whenever fileparts returns empty Yeah, I added that, but still ran into other issues. For example, if the filename is "\test.txt", fileparts returns empty rather than blackslash. So that messes up detection logic. Also, "C:\test.txt" and "C:test.txt" both return C:\ for the path. So it's hard to differentiate between those cases. I think I'm giving up with a generic fool-proof way of detecting the path.
From: Bruno Luong on 23 Mar 2010 17:29 "Jon Harris" <jonharris7_remove(a)gmail.com> wrote in message <hobbed$e71$1(a)fred.mathworks.com>... > > > Yeah, I added that, but still ran into other issues. For example, if the filename is "\test.txt", fileparts returns empty rather than blackslash. This is a bug of fileparts in older Matlab version. If you have recent Matlab it's OK. Bruno
From: us on 23 Mar 2010 17:43
"Jon Harris" <jonharris7_remove(a)gmail.com> wrote in message <hobbed$e71$1(a)fred.mathworks.com>... > "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hobb1a$7ga$1(a)fred.mathworks.com>... > > > This seems to work fine with relative or absolute paths. But if the file is just a name, I get this: > > > > > > » file='test.txt' > > > file = > > > test.txt > > > » fullpath=cd(cd(fileparts(file))) > > > ??? Name is nonexistent or not a directory > > > > Easy to fix if you check whenever fileparts returns empty > > Yeah, I added that, but still ran into other issues. For example, if the filename is "\test.txt", fileparts returns empty rather than blackslash. So that messes up detection logic. > Also, "C:\test.txt" and "C:test.txt" both return C:\ for the path. So it's hard to differentiate between those cases. > I think I'm giving up with a generic fool-proof way of detecting the path. well... there IS one more option you should look at... - assuming your winsys runs a .NET version fp=fopen('foo.m'); fnam=System.IO.DirectoryInfo(fopen(fp)).FullName % fnam = F:\usr\matlab\tmp\ng\ngfile\foo.m fclose(fp); fp=fopen('./foo.m'); % <- note: forward slash allowed... fnam=System.IO.DirectoryInfo(fopen(fp)).FullName % fnam = F:\usr\matlab\tmp\ng\ngfile\foo.m fclose(fp); fp=fopen('f:foo.m'); fnam=System.IO.DirectoryInfo(fopen(fp)).FullName % fnam = F:\usr\matlab\tmp\ng\ngfile\foo.m fclose(fp); us |