Search code examples
pythonpython-3.xmacosmacos-mojave

Changing the display name of a file


How can I change the display name of a file using Python?

Details:

  • Using Mac OS X Mojave
  • Python 3.7

To be precise, I want to hide the file extension of a file so that textfile.txt is seen as textfile only, without actually removing the file extension.

EDIT: The display name of a file looks like this:

Image

And I want it to look like this:

Image


Solution

  • What you want is

    import os
    print(os.path.splitext("/path/to/textfile.txt")[0])
    

    The output will be

    /path/to/textfile
    

    EDIT: from your last edit i figured that what you're looking for is to hide extensions directly in the OS using Python. Well, this is more a task to do modifying your system settings, i don't think that you will be able to change this type of system settings directly from Python.