Why are sketch filename hyphens '-' converted to underscores '_'?

The cause of an issue I was having when searching my sketch folders turned out to be that my filenames had hyphens unceremoniously converted to underscores when saved. So my RotEnc-LCD-Uno-NoDFR.ino became RotEnc_LCD_Uno_NoDFR.ino. Yet in their original form they were causing no apparent problems.

So is the '-' character technically 'disallowed' in sketch filenames, yet tolerated?

Hi @Terrypin. The Arduino IDE developers are tracking this bug here:

If you have a GitHub account, you can subscribe to that thread to get notifications of any new developments related to this subject:


:red_exclamation_mark: Please only comment on the GitHub issue thread if you have new technical information that will assist with the resolution. General discussion and support requests are always welcome here on the Arduino Forum.


No, it is explicitly allowed:

https://arduino.github.io/arduino-cli/latest/sketch-specification/#sketch-folders-and-files

The sketch root folder name and code file names must start with a basic letter (A-Z or a-z), number (0-9)1, or underscore (_) 2 followed by basic letters, numbers, underscores, dots (.) and dashes (-). The maximum length is 63 characters. The sketch name cannot end with a dot (.) and cannot be a reserved name.

1 Supported from Arduino IDE 1.8.4.

2 Supported in all versions except Arduino IDE 2.0.4/Arduino CLI
0.30.0 - 0.30.1.

Thanks @ptillisch , understood. Over two years. Any fix likely soon?

This is something only a project manager could answer. I am not involved in setting development priorities and allocating resources for the Arduino company, so I don't have any insight into this.

My role is to ensure the bug reports and feature requests are properly tracked, and supporting the users in the use of the software we have now - warts and all.

The sketch naming convention established by Arduino is to use "PascalCase" (AKA "UpperCamelCase"). If you follow that naming scheme, you won't be affected by the bug.

Thanks. Ok, i’ll have to try to consistently use one of my current three alternatives: camel case, hyphens, or underscores.