Using F2 to rename a file can cause the file to have a filename too long so it can't be accessed. This bug has two possible outcomes.

As you might already know, under Windows the complete path to a file must be under MAX_PATH which currently is 260 characters. That includes drive letter, all folders and slash separators, and the file's name and extension (unlike in old 8.3 fashion, period does count too). Usually you shouldn't be able to deal with files longer than this limit, unless you're using certain API functions which it seems you do. However, these functions aren't used consistently across all the libraries used by XMP, and outside XMP it's kind of rare. The normal way to find this problem is moving a folder which has a file near the limit inside a folder which with its combined name length causes the file to exceed the limit. Without special software you can't access these files, but you can always move to root the folder which has the file for a simple rename (or from now on, use XMP).

In the case of XMP, you can rename directly a file so it's complete path is longer than the limit. This can happen in two ways. First, we can try to rename to a filename with extension which is longer than the limit. In such case, XMP shows the overwriting file panel, without any file information, not knowing to do with such a long filename.

And second, we can rename a file with a name shorter than the limit, but still with complete path longer than the limit. So if the name is 240 characters long, and it's inside a 10 character long folder, and when renaming we add 15 chars more, XMP will happily rename it, and read the thumbnail, but you will not be able to see the image (neither trying to launch it from the browser, which shows a blank screen, nor from outside XMP, which shows a 'file not found' error from XMP. However with XMP you can rename the file back to shorter than the limit.

My suggestion is that while renaming a file, each time the text changes, you calculate the complete path length and if it's larger than MAX_PATH, crop the last chars of the name (without touching the extension) so it is still accessable both to XMP and to any other program without giving problems. You could even add an option to specify how many 'safe characters' are between the limit and the maximum length that XMP will allow to rename.

I haven't tested with the autorenamer since I use another specific tool for that and I'm not familiar with yours. I'd also check name and path length limits for the other OS XMP is released for.

JMM72 wrote:First, we can try to rename to a filename with extension which is longer than the limit. In such case, XMP shows the overwriting file panel, without any file information, not knowing to do with such a long filename.

I could reproduce this problem by renaming an image file to this:
"My Image with 265 charachter filename 901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.jpg"

JMM72 wrote:And second, we can rename a file with a name shorter than the limit, but still with complete path longer than the limit. So if the name is 240 characters long, and it's inside a 10 character long folder, and when renaming we add 15 chars more, XMP will happily rename it, and read the thumbnail, but you will not be able to see the image (neither trying to launch it from the browser, which shows a blank screen, nor from outside XMP, which shows a 'file not found' error from XMP. However with XMP you can rename the file back to shorter than the limit.

Tested bij renaming a file with XnViewMP (F2) to something with <250 characters>.jpg, in a path of 15 characters.
I understood XnViewMP wasn't supposed to allow that anymore.

In version 0.86 the thumb of the long filename file isn't shown and the file cannot be opened.
In 0.87 the thumb is shown, but the file cannot be opened, message File can't be loaded.
In Windows Explorer the file cannot be deleted, not even renamed...

Only after renaming the file in XnViewMP, shortening it 20 characters, the file can be handled again.

In Windows Explorer, when typing a filename, the input just stops after the max amount of characters.
When pasting a too long name in the rename dialog, the string is truncated.

But it depends on how you test.
Because it it not easy to test by counting 250 keypresses or so, I used an editor and types a filename with 250 characters, looking at the column counter of the editor. Then I copy/pasted that 250 character string into the Rename dialog of XnViewMP.
If you start typing a long filename in the Rename dialog of XnViewMP, it's different.

So please test yourselves with the following procedures:

Still possible to rename:
Copy/paste a 250 character string into the Rename dialog of XnViewMP. The name is accepted, the file is renamed, but not accessible

Not possible to rename:
Copy/paste a 257 character string into the Rename dialog of XnViewMP. A message "An error occurs during rename!" appears.
SO: only the filename length is checked, NOT the complete path.

You could if you wish edit the above post, either pasting in the long names (if that works satisfactorily) or attach a suitable file (a text file would have to be placed in a ZIP or similar archive, I think).

Just paste that string above in the Rename dialog box and press OK.
The file s renamed, which shouldn't be possible.
The file cannot be opened with XnViewMP and not with Windows explorer.
Luckily it can be renamed back to something short with both applications to get access again.

Tested again:
Used a directory D:\1234567890
Copied a file in that directory and started the rename process.

- A filename of more than 260 characters long cannot be entered in the File rename field.

- A filename of 260 characters can be entered, but when clicking OK, the message An error occurs during rename! appears.

- A filename of 252 can be entered and is accepted. This is the longest filename accepted by XnViewMP, no matter where the file is, so for example in the root. But in this example the file is in D:\1234567890 and it cannot be handled by Windows Explorer.
The total path:
D:\1234567890\1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 123456789.JPG

- Shortened the filename until it could be handled by Windows Explorer that was when the total path length was 260 characters, so the filename in this example was 242 characters.
The total path of the longest Windows-accepted filename:
D:\1234567890\1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890.JPG