Bug with copyfile for matlab 2015b related to string length "The system cannot find the path specified." - Question still unresolved

1 回表示 (過去 30 日間)
jeff
jeff 2016 年 3 月 7 日
コメント済み: Jan 2016 年 9 月 28 日
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
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
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
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?
  1 件のコメント
jeff
jeff 2016 年 3 月 9 日
Yes it finds it in both cases, but it only has the problem when trying to execute copystat. (I was running it in a loop to do multiple files and 4 was the failure because the name was longer. Same results outside of a loop though.)
Here is everything I was trying:
K>> exist(destination)
ans =
7
K>> exist(['\\?\' destination])
ans =
7
K>> clear copystat
for ii = 1:size(cont,1)
[copystat(ii), ~] = copyfile(['\\?\' parameters.inputdir cont{ii,1}],[destination])
end
copystat =
1 1 1 0 1 1
K>> clear copystat
for ii = 1:size(cont,1)
[copystat(ii), ~] = copyfile(['\\?\' parameters.inputdir cont{ii,1}],['\\?\' destination])
end
copystat =
0 0 0 0 0 0
In the first case I got the error "The system cannot find the path specified." on number 4.
In the next case I got the error "The filename, directory name, or volume label syntax is incorrect." on all them.

サインインしてコメントする。


Image Analyst
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
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.
jeff
jeff 2016 年 3 月 11 日
I didn't know about this, but there is still the exact same result with forward slashes.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by