Skip to content

Rename special/unsupported characters in filenames #1734

Description

@Zillode

As mentioned in syncthing/syncthing-android#192 , some filenames are not accepted by windows hosts because they contain 'special characters' like colons or bars.

@schuft69 suggested to add a "Rename special characters to '_'" option to resolve this issue.

< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

Activity

  1. calmh commented on Apr 29, 2015

    @calmh
    Member

    This needs to happen on the source then, or we need to keep the translation in the database somewhere, and hilariousness ensues when the database is reset or lost.

  2. neclepsio commented on May 4, 2015

    @neclepsio

    Maybe there could be a warning on the source, inviting to rename the file to avoid problems.

  3. somasis commented on May 4, 2015

    @somasis

    I would think that with the substitution of characters it wouldn't really be required on each machine's database... would it not be possible to just check files incoming/outgoing against the substituted version, if they exist already on the host or don't, do what's appropriate?

  4. jeremy-audet commented on May 4, 2015

    @jeremy-audet

    I would think that with the substitution of characters it wouldn't really be required on each machine's database... would it not be possible to just check files incoming/outgoing against the substituted version, if they exist already on the host or don't, do what's appropriate?

    No. Consider a case where a *nix machine has two files in a directory, and their contents are unique:

    $ echo 'first file' > 'foo:bar'
    $ echo 'second file' > 'foo>bar'
    $ ls -1
    foo>bar
    foo:bar
    $ cat 'foo:bar'
    first file
    $ cat 'foo>bar'
    second file

    Simply renaming each file by substituting offending characters would not work. You would end up with two conflicting files, each named foo_bar.

    Also, consider this scenario:

    1. A user has a *nix machine with a file on it named foo:bar.
    2. The user adds a Windows machine to the syncthing cluster. The file is copied to the Windows machine as foo_bar.
    3. The user adds a second *nix machine to the syncthing cluster. This second *nix machine receives a file named foo:bar from the first *nix machine and a file named foo_bar from the Windows machine.

    Oops. One file magically became two files.

  5. neclepsio commented on May 4, 2015

    @neclepsio

    Moreover there are other forbidden names under Windows: for example, nul or com1 and several other, or names longer than 255 characters. And names cannot end with a dot or space. And Mac could be a problem too: I think it requires normalized unicode, while in Linux normalized and non-normalized version could be two different files. (I'm just remembering, cannot verify right now, maybe there are some imprecisions).

  6. calmh commented on May 4, 2015

    @calmh
    Member

    We enforce unicode normalization; there's been some pain around that, for people having files with the "wrong" normalization for their OS. There we actually silently fix it, unless configured otherwise.

    for example, nul or com1 and several other, or names longer than 255 characters. And names cannot end with a dot or space.

    😱 I'd forgotten about the first of that, and didn't know about the second. We should probably handle that too (at least with a reject). Dammit, Windows...

    But @Ichimonji10 above summarizes quite nicely why we probably won't be doing character substitutions anytime soon.

  7. neclepsio commented on May 5, 2015

    @neclepsio

    Just to add all the information in one place: you have to handle case sensitivity too.

    Moreover, the problem is not with Windows bit also affects NTFS with other OSs. While in Linux shares under Windows have an error if trying to create a wrong filename, direct NTFS mounts do not have errors by default, and files are accessibile under Linux but not under Windows. So, you cannot rely on errors to know if a filename is legal.

  8. kozec commented on May 5, 2015

    @kozec
    Contributor

    This is maybe even crazier idea, but how about simple escaping? On windows, invalid character in incoming file names can be substituted, All*files? to All^afiles^q, for example, and reversed substitution can be used for outgoing files. Substitution may be configurable per-repository and enabled on Windows by default, so this would help even with samba mounts on *nixes.

  9. calmh commented on May 5, 2015

    @calmh
    Member

    We could do escaping, but it would have to be to something the user would not enter herself (to avoid confusion), and it would be ugly. I.e. foo:bar -> st--foo%3abar. The point being that we should be able to recognize the escaping even if the database is gone and we're doing an initial scan. I have files with legitimate ^'s in them (well, legitimateness can be debated, but they are there) and probably the same goes for someone else and whatever other character we could think of.

    The case sensitivityness is an open bug somewhere else.

    And I don't think should try to guess hidden rules when the OS and filesystem are fine with them...

  10. kozec commented on May 5, 2015

    @kozec
    Contributor

    I have files with legitimate ^'s in them (well, legitimateness can be debated, but they are there) and probably the same goes for someone else and whatever other character we could think of.

    True, but that can be "solved" by escaping escape character, so incoming file^2 would become file^^2. Of course, if user manages to create file^a manually on Windows machine, Linux will receive file*. I can't argue it's not ugly, but it's not ambiguous.

    There is also thing that cygwin does - they are translating invalid characters to character from unicode private space. That may, in plain theory, create conflicts, but chances are really slim and it looks better.

  11. calmh commented on May 5, 2015

    @calmh
    Member

    To be honest, I think the much simpler solution is for people who sync across multiple OS:es to just stick to the lowest common denominator in file names or live with the errors. It's not that onerous, and people using more than one platform should be kind of aware of the issue. For cases where someone has just a Windows box and a NAS running Linux, they'll most likely create all their files from the Windows side and automatically stay within the limitations.

    (The case sensitivity thing still needs to be handled better though.)

  12. neclepsio commented on May 5, 2015

    @neclepsio
  13. kozec commented on May 5, 2015

    @kozec
    Contributor

    I think the much simpler solution is for people who sync across multiple OS:es to just stick to the lowest common denominator in file names or live with the errors.

    There are two problems with this approach.

    1. Sometimes user can't choose what characters are included.
    2. User usually realizes that [:-)] is invalid Windows filename only after he can't find it on other side. And that may be especially sweet realization if source machine is already offline.
  14. calmh commented on May 5, 2015

    @calmh
    Member

    I don't see point number one related to syncthing; that'd be a problem for the poor user on Windows with someone forcing invalid filenames on him no matter the delivery mechanism? Point number two implies the user is also a Linux user, who I'm assuming are more aware about things like filesystems and name limitations?

  15. calmh commented on May 5, 2015

    @calmh
    Member

    (This is all to say that I think this should be solved in a clean way, not that we shouldn't solve it at all. But something that is really ugly or has bad side effects is probably not worth it IMHO.)

  16. 63 remaining items

  17. added a commit that references this issue on Jun 9, 2025
    c8d7b19
  18. added a commit that references this issue on Aug 8, 2025
    ee86a2a
  19. added a commit that references this issue on Mar 9, 2026
    1f3dd3b
  20. added 5 commits that reference this issue on Mar 18, 2026
    25d67f1
    2452f6c
    41e7197
    4d343c5
    e842774
  21. added a commit that references this issue on May 2, 2026
    f00d4ed
  22. added a commit that references this issue on May 30, 2026
    e79637a
  23. added 2 commits that reference this issue on Jul 27, 2026
    0a5a95d
    20c606d
  24. added 2 commits that reference this issue on Sep 9, 2026
    3290520
    ecbea3c
  25. added a commit that references this issue on Nov 18, 2026
    5e77d54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions