필터 지우기
필터 지우기

Copyfile with long path names

조회 수: 127 (최근 30일)
Christoph
Christoph 2013년 5월 22일
댓글: Martin 2024년 4월 24일
There seems to exist a limitation for the length of the file path when using the copyfile-command (something like 260 characters), because I get an 'Unknown error' when I want to copy to a destination with a longer path.
This seems to be related to a problem with the Windows copy+paste command (because I cannot even manually copy the files to that location). I googled the problem and it seems that there exist some workarounds for manual copy+paste. Do you know of any workarounds for this problem in Matlab?
My system: Windows 7 64-bit Matlab R2013a
  댓글 수: 8
John
John 2024년 4월 23일
Yes, I have. Just Google it and you will find everything. It is easy btw.
Martin
Martin 2024년 4월 24일
I just installed the tool. I will soon share the reviews.

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

채택된 답변

Jan
Jan 2013년 5월 22일
편집: Jan 2013년 5월 22일
It is not a problem of Copy&Paste, but file names have this general limitation under Windows. E.g. the Windows Explorer cannot move files to the recycle bin, if their name is longer.
As workaround you can use the Windows API function and mask the name with the leading magic string '\\?\'. But a lot of important functions (like the already mentioned recycling) will not work. Even e.g. DIR fails for too long path and/or folder names (at least here the masking works, see also FEX: GetFullPath). Therefore I suggest three strategies:
  1. Write an enhancement request to Microsoft. This is such a dull and idiotic limitation, which blocks a serious using of the system since the first DOS implementations. Try to reach Bill Gates personally, because he is responsible.
  2. Use a serious operating system for serious tasks. Linux, Unix, Aix, BeOS, HP-UX, MacOS (7,8,9,X), Minix, BSD, Solaris, VMS, and even the Sinclair ZX Spectrum (1982) had no such limits in the file name length.
  3. Use shorter file names, when you insist on using Windows for considerable reasons.
Note that very long file names usually mean, that the user inserts important information into the name, instead of storing it in the contents. But it is not efficient to store important information in the filesystem's name tables. A slightly exaggerated example: You can even store pictures in the name tables by using spaces and X as black&white pixels and using a very small font size for the command window, where the LS command is called. But then you cannot blame the OS, if you cannot use duplicate pixel rows or if the output is dosplayed in alphabetical order.
PS. Sometimes I think of inserting smilies in my messages, but I still hope my English is distinct enough to let the readers understand the intention without such extra markers. Of course I know, that Bill will no answer, but I'm impressed every time TMWs technical support responses to such enhancement requests.
  댓글 수: 2
jack reacher
jack reacher 2017년 12월 15일
use robocopy
Walter Roberson
Walter Roberson 2017년 12월 15일

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

추가 답변 (2개)

Friedrich
Friedrich 2013년 5월 22일
편집: Friedrich 2013년 5월 22일
Hi,
have you tried to prefix \\?\ for the file path like mentioned here:
AFAIK MATLAB calls into the WIndows API function when using copyfile. At least my MATLAB doesnt complain when I build up a file path like
a = '\\?\C:\myfolder\test.dat'
copfyile(a,'C:\demo.dat')
And it also works. Does this work for you?
  댓글 수: 5
Jan
Jan 2013년 5월 24일
편집: Jan 2013년 5월 24일
The magic (another word for ugly here) string '\\?\' helps also, for scanning folders with long pathes by the DIR command. Unfortunately it is not the 260 characters limit, but some characters less. The length of the file names might matter also, but it cannot be known before getting the list. After some user requests, I've expanded GetFullPath, such that it can handle this securely:
List = dir(GetFullPath(Folder, 'fat'));
KAE
KAE 2018년 1월 8일
In case it helps someone else, here is an example for the move command if you need to move a file with a long name to a subdirectory resulting in an even longer name so that the final filename would exceed the 260 character limit. There are double quotes to deal with spaces in the file or directory name.
eval(['!move "\\?\' longFilename '" "' subdirectoryMakingLongerFilename '"']);

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


Iain
Iain 2013년 5월 24일
I'm not sure how you can reasonably use this or if it still exists in Win7.
There is a "short" name for every file and folder, which is restricted to 8 characters.
C:\docume~1\ is the short path for C:\documents and settings\.
It gets extremely hard to use if you have huge numbers of similarly named files, because the "~1" part gets longer and more complicated.
  댓글 수: 1
Jan
Jan 2013년 5월 24일
Fortunately the Windows API offers method to get the short name automatically, such that a simple Mex-File can achieve the conversion. But even the short name must fail, when the path of a file is deeply nested and even the resulting short name exceeds MAX_PATH characters. In addition error messages containing the abbrev. filename will look such ugly.

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by