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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Jean Marçais
Jean Marçais am 27 Sep. 2016
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 am 28 Sep. 2016
@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?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jan
Jan am 9 Mär. 2016
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 Kommentar
jeff
jeff am 9 Mär. 2016
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.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 11 Mär. 2016
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 Kommentare
Image Analyst
Image Analyst am 11 Mär. 2016
Something to try: use forward slashes instead of backslashes. Believe it or not, Windows understands forward slashes in filenames perfectly fine.
jeff
jeff am 11 Mär. 2016
I didn't know about this, but there is still the exact same result with forward slashes.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by