Home Blog Tools Contact

How many characters can a file name contain?


Character means a single object used to represent text, numbers, symbols, or special characters. For example, the letter "a" is considered a single character, and the word "file976" is considered a string with 7 characters.

Filename

The filename is considered as a collection of characters to a unique identifier of the file in the electronic devices (e.g: computers, Phones). Two files in a same directory can not have same filename, but two files in different directories can have same filename.

characters in different filepath can be same

Filename structure differs based on the usage and operating system of the devices. Commonly, a filename will have

  1. Name - Primary name of the file
  2. Extension - An extension to express the type of the file/execution pattern of the file/content of the file.

Name and extension are usually merged together by dot(".") to generate a common filename of the file.

Name Extension Filename Description
 computer  .png  computer.png Usually .png extension refers to image content
 mycomputer   mycomputer   Some files can be without extension too
 application  .exe application.exe   Usually .exe refers to executable content
   .env  .env  Usually .env refers to environment properties content, and name will be empty
 app.test  .js app.test.js   Usually .js refers to JavaScript content file, and name also can have dot among the letters.

Filepath vs Filename

There is a confusion among filepath and filename. Actually filepath refers to the pathway from the origin of the user / operating system / startup folder to the current file, where filename refers to just the name of the file.

  • /app/sample/demo.pdf refers to a filepath of a file called "demo.pdf"
  • Here, demo.pdf is the filename of the file

Length of a filename

There is no universal rule that a filename can have this kind of letters or can only have this length of characters. But there is a limitation for the filename length on each operating system / runtime environment to support their internal strctures and data management.

Operating System / Runtime Requirement Filename maximum length
 IBM S/370 44 
 FAT 12 System 11 
 Early days of Unix  14
Latest Unix  255
NTFS file system(Windows) / Mac OS   255

Each operating system holds an internal data management nature with a larger scope to handle the files, and directories efficiently for the user actions. Each file will have the contents, and also will have some metadata like file name, file size, file extension, created, etc. Meta data also will share some space from the storage to hold the file meta-data information, and will be used when ever it needed. In common practices, it's not advisable to keep the open limits for any data storage components, as it should have lower limit and upper limit. Likewise, the filename property also have a constraint as lower limit(minimum) and upper limit(maximum), which varies based on the operating system / runtime environment.

Most operating systems / runtime environments don't allow the users to customize the filename lengths, unless if it's a very customized environment for a specific usecase. Changing the filename length restrictions may affect the existing file's meta-data as well as allocated storages for the existing file meta data-conents - it's an extensive time consuming operation!

  • The releases of Windows before Windows 10, the maximum length for a path is MAX_PATH, which is defined as 260 characters. In later versions of Windows, changing a registry key or using the Group Policy tool is required to remove the limit.

Filename conventions

Filenames are considered as non-case sensitive components at all times, but in several cases it might be treated as case sensitive component (highly secured systems). E.g: Apple.png, APPLE.png, apple.png are referring to the same file.

Filenames can have any characters (letters, numbers, special characters) expect the following reserved charters.

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

Filename can have unicode characters as well. Some examples are

  • APPLE©.png
  • 漢字.png
  • கணினி.png

File transfer issues related to filename lengths

Let's assume there are two systems A, and B having two different filename constraints as follows

  • System A has a restrictions as max file length of 120 letters
  • System B has a restrictions as max file length of 240 letters

If you are copying or moving a file from System A to System B, there won't be any issues related to filenames as System B's filename can have more characters than System A's filename. Let's consider, if you are copying or moving a file from System B to System A where the filename has a length of 180 characters. You might get the following when you are initiating the action,

  • "The file can not be moved" error message in your System B screen
  • The file will be moved to System A with a truncated filename depends on the System A filename restrictions.

Each system follows their internal definitions to follow the pattern of adoption when there is a conflict in filename lengths.