Bug with copyfile for matlab 2015b related to string length "The system cannot find the path specified." - Question still unresolved
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to move files from one folder to another and I am getting the error "The system cannot find the path specified." Both paths exist and I am pretty sure there is a glitch related to string length. I am calling out the function like so:
% move files
[copystat, err] = copyfile([parameters.inputdir cont],destination);
where the error will be thrown if :
cont = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX_20151217_143010.raw
but not if:
cont = XXXXXXXXXXXXXXXXXXXXXXXXXXXX_20151217_143010.raw
There is only 1 character different in these two. Also all strings longer than this will throw the error too. The longest string that will work is 143 characters for [parameters.inputdir cont]. I am assuming it is an issue with string length because of this and was hoping someone out there would have an idea for how to allow longer strings.
Any help is greatly appreciated.
EDIT: I found out more information related the issue... I noticed that size(destination) is 210 char. So size([destination '\' cont]) is 261 char. I tried adding the long path to destination so my code is now:
[copystat, err] = copyfile(['\\?\' parameters.inputdir cont],['\\?\' destination]);
but this doesn't seem to work either and throws a different error: "The filename, directory name, or volume label syntax is incorrect."
but this is the same destination that used to work with shorter names (without the \\?\). Also it won't even copy shorter paths over (same error). Is the \\?\ not allowed on destination for some reason?
Note: I also tried
[copystat, err] = copyfile([parameters.inputdir cont],['\\?\' destination]);
and got the same error.
9 件のコメント
Jean Marçais
2016 年 9 月 27 日
Hi, I have exactly the same problem... Do you have resolved this issue? It seems to me it is not only the string's length that matters, as I kept having the same error with short string while it's copying the file for longer string.
Jan
2016 年 9 月 28 日
@Jean: In the OP's case the string length was the problem. If this is not the problem in you case, you do not have exactly the same problem. Please post the name of the failing files. Do they contain unicode characters? Did you check, that the file names are valid? No stars, no colons, no question marks etc?
回答 (2 件)
Jan
2016 年 3 月 9 日
Perhaps Fex: GetFullPath is useful to insert the specifier for long file names automatically. But the error mesage
The filename, directory name, or volume label syntax is incorrect.
might point in another direction: Are the path names really valid file names?
Image Analyst
2016 年 3 月 11 日
Certain programs have their own limits, like Excel's 218 character limit for filenames. Who knows why? I do not know if MATLAB has a similar limit or what it might be if it has one.
3 件のコメント
Image Analyst
2016 年 3 月 11 日
Something to try: use forward slashes instead of backslashes. Believe it or not, Windows understands forward slashes in filenames perfectly fine.
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!