Maximum Length allowed in fopen/movefile??

Please tell me how much maximum character limit is permitable in the fopen /movefile commands?? I have a situation in which I have to open a text file in write mode whos name length is about 269 characters. but fopen returns me -1. Can you please tell me how much maximum characters are allowed in movefile/fopen commands.
Total (259)= Path (130 character) / Filename (129 character)
fopen gives me -1
any help??????

3 Comments

dpb
dpb on 2 Feb 2017
Edited: dpb on 3 Feb 2017
Until Windows 10, maximum total filename length was 255 characters; I don't know for a fact but I suspect any limit is not actually in Matlab but the underlying OS.
ADDENDUM
You really, really, really ought to fix whatever it is that is generating such long filenames.
You can work around the issue by doing a cd to the directory containing the file(s) and then creating a shorter name from the original keeping, of course, sufficient discernment to make them unique. If nothing else, make a text file containing the original current name and then rename the files sequentially and use the corresponding entry in the text file to retrieve the necessary information from the current name.
But surely there's a way to keep the necessary identifiers within the name but shorten it to well under 130 characters or so so the fully-qualified name is also well under the 255 limit.
Actually, the limit is 260 characters including drive letter. 255 indeed for the path without drive letter.

Sign in to comment.

Answers (2)

fopen(['\\?\', yourpath])
may work for you.
Though as dpb says, such long paths would be better avoided as some tools (including windows file explorer) don't cope well with it.
2^64 - 1 bytes for the entire move command on some Linux systems. 4095 per file is not uncommon on Linux systems. Historically, 1023 per file on Unix derivatives was common.
But if you are using MS Windows and not using the \\?\ prefix then 255+5 per file.

1 Comment

Huh. I'd never run across the \\?\ prefix before...

Sign in to comment.

Commented:

dpb
on 4 Feb 2017

Community Treasure Hunt

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

Start Hunting!