Incorect output from the "fileparts" function

Hi everyone
Here is a quick shot of my current problem:
I simply don't understand why the following commands:
Filename = 'Animation_28-Nov-2012 01:06:20_.avi';
[pathstr, baseFile, extProvided ] = fileparts(Filename);
are giving the following results:
pathstr = Animation_28-Nov-2012 01:06:\
baseFile = 20_
extProvided = .avi
Indeed, as you can notice, after the second ":" character is added a "\" which is interpreted as the file path of the file.
Why is there a "\" character ?! I simply don't understand. I tried to go through the help file but without any success.
Any idea would be very helpful, thank you for your help.

댓글 수: 1

John Petersen
John Petersen 2012년 11월 28일
편집: John Petersen 2012년 11월 28일
What OS are you using? Windows doesn't allow colons (:) in the filename. So it seems that fileparts understands the text up to the last : to be the path and the rest of the string to be the filename.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2012년 11월 28일

0 개 추천

In MS Windows, colons in filenames indicate device prefixes.
You can read the source code for fileparts. When executing on MS Windows, if there is no / or \ in the name, then the path is considered to extend to the last ':'

추가 답변 (2개)

Greg
Greg 2012년 11월 28일

1 개 추천

Oooookay well done guys. Indeed this code was executed on Windows 7.
For the record I simply added this line before, in order to clean "Filename":
Filename = regexprep(Filename,'[: ]','-');
Thanks for all your answers and comments guys!
per isakson
per isakson 2012년 11월 28일

0 개 추천

Windows 7 help says:
Which characters can't be used in a file name?
You can't use any of the following characters in a file name: \ / ? : * " > < |
However, on a Windows system it is possible to create files, with invalid names. Don't ask me how, but I know because I get such files sent to me.
Obviously, filepart doesn't check for the validity of the file name.

댓글 수: 2

Jan
Jan 2012년 11월 28일
While "C:\" is the disk C, "C:" is the current folder on the disk C. Therefore Matlab appends a backslash after a colon.
You can create invalid filenames using the low-level functions. The most ugly way is to write directly in the name table of the file system. It's like using a MEX function to create field names like the empty string or a space. It works using dynamic field names: "S.('')", but of course Matlab is driven out of its specifications and crashs must be expected.
Daniel Shub
Daniel Shub 2012년 11월 28일
I think these limitations are due to Windows and not the filesystem (NTFS). I am pretty sure if I mount an NTFS filesystem with Linux I can create these "invalid" names pretty easily.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Search Path에 대해 자세히 알아보기

제품

태그

질문:

2012년 11월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by