MEGAsync icon indicating copy to clipboard operation
MEGAsync copied to clipboard

[bug] Tailing spaces in filename breaks Windows Explorer

Open AlttiRi opened this issue 2 years ago • 6 comments

Trim tailing spaces

The most annoying bug with MEGAsync is downloading of files/folders with a tailing space(s).

In this case MEGAsync successfully downloads the file, but Windows Explorer can't correctly work with this files.

I can't move, rename, delete the files, or open thought Windows Explorer it.

Yeah, it's a valid NTFS filename, but it's not a valid Windows' filename.

Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. However, it is acceptable to specify a period as the first character of a name. For example, ".temp".

https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

I sure, 99.9 % of Windows users will work with the downloaded files with Windows Explorer and they will face this bug.

Currently for such cases I need to use 7zip, I archive them in a temporal archive with "Delete files after compression" option, then unpack it back. 7zip replaces the tailing space with _ character.


Just add a tailing space in a filename on mega.nz for any file, then download this file with MegaSync.

Then try to open, rename, deleted it. You will can't.

Windows, 4.6.6.

AlttiRi avatar Jun 21 '22 20:06 AlttiRi

Dear AlttiRi, hopefully one day Microsoft's own filesystem browser will work properly with its own filesystem. In the meantime, if you are using your MEGA account from windows, you do have the option to avoid putting spaces on the end of filenames yourself. If we did implement such a function, you'd no longer have an exact 1:1 correspondence with the files in MEGA. Also there may already be a file with that name (the one that removes/converts the space). Overall it would be a messy result. Also, if you must cause yourself troubles by making filenames with trailing spaces when you know you'll be using them on windows, you can always work with them in windows via command line, using full paths and prefixing those paths with \ \ ? \ (remove the spaces between those characters first) thanks

mattw-mega avatar Jun 21 '22 21:06 mattw-mega

At least don't allow to create such files in the web interface. More over show the warning if such files were found, ideally, with the recursive search.

The main reason when this problem appears when someone decided to edit a filename in the web interface and leaves the tailing space accidentally.

AlttiRi avatar Jun 21 '22 22:06 AlttiRi

Even Ubuntu's file explorer trims the tailing space if you create a file with it.

I sure that almost all files with the tailing space were accidentally created by editing the filename in the web interface. Who in their right mind would create such files on purpose? (even on Linux)


Also I don't create such files, I talk about the problem from the point a user that usually downloads artist's artworks.


The most of users are Windows' users.

AlttiRi avatar Jun 21 '22 22:06 AlttiRi

That is a good point, I see the webclient allows such a renaming, with no warning if a space was left at the end of the name. Given it could be a common mistake, especially with copy-paste from somewhere else when accidentally selecting slightly too much text, probably we should confirm with the user for such a case. (We should allow the user to do it though, if they want to for their own reasons, spaces are allowed in names generally - and not everyone uses windows)

mattw-mega avatar Jun 21 '22 22:06 mattw-mega

I will pass this feedback to the webclient team

mattw-mega avatar Jun 21 '22 22:06 mattw-mega

Funnily enough, I just google searched this issue (trailing spaces) which led me here... I use macOS (Monterey) 12.4... I don't know if the issue is MegaSync OR the files themselves in a Mega Folder named badly, but when I download files via MegaSync recently 99% of the time there's a trailing space on the full filename with extension. This results is Pictures (jpg, png for example) and movies (mp4 for example) not being recognised

The files are being saved as imagename.jpg(space) or videoname.mp4(space) -- where (space) is an actual space. I have to manually remove the trailing space from the extension which is extremely time consuming (I suppose I could write a script but not looked into that yet) before Finder will recognise the files

On macOS at least I CAN move, rename etc the files no problem, it's simply that Finder doesn't recognise them as valid file types, therefore Quicklook etc doesn't recognise them. Since jpg(space) is obv not an actual file extension

In fact, on macOS I can just use this and it works recursively (So ultimately not time consuming at all now I've figured out the terminal command - but the bug itself is still annoying)

find . -depth -name '* ' -execdir bash -c 'mv "$1" "${1%"${1##*[^[:space:]]}"}"' Move {} \;

IAmOrion avatar Jul 05 '22 19:07 IAmOrion

Hi, you can rename to remove trailing spaces in windows. Just use the command line, as Explorer is a bit useless for this. Perhaps if enough people complain to Microsoft, they will make it compatible with their own filesystem. And, there is always the option to name your files to be compatible with Explorer if you are going to use them on windows. Anyway, here is how to do it. Note the quotes around the full path or the name, if it contains a trailing space (and this will work for trailing dot too). And use the prefix \\?\ in order to send the request direct to the filesystem:
image

mattw-mega avatar Feb 06 '23 23:02 mattw-mega