Opening a folder that contains spaces

Started by Dave T., April 14, 2023, 02:04:24 AM

Previous topic - Next topic

Dave T.

Hi all,

Does anyone have any tricks to allow a folder to be opened (that contains spaces) with the os.Path.dirOpen method on a Windows client ?

Cheers

Dave

william s.

Quote from:  . on April 14, 2023, 02:04:24 AM
Hi all,

Does anyone have any tricks to allow a folder to be opened (that contains spaces) with the os.Path.dirOpen method on a Windows client ?

Cheers

Dave

To open a folder with spaces using the os.Path.dirOpen function on a Windows client, wrap the folder path in double quotes. This ensures that the entire path is handled as a single item, with the spaces not construed as separators.

For instance, if the folder location is "C:\Program Files", you can open it with the following code:

import os

folder_path = 'C:\\Program Files'
os.startfile('"{}"'.format(folder_path))

This will open the folder without any problems due to gaps in the path.

wilkinson w.

Quote from:  . on February 23, 2024, 03:20:28 AM

To open a folder with spaces using the os.Path.dirOpen function on a Windows client, wrap the folder path in double quotes. This ensures that the entire path is handled as a single item, with the spaces not construed as separators.

For instance, if the folder location is "C:\Program Files", you can open it with the following code:

import os basketball stars

folder_path = 'C:\\Program Files'
os.startfile('"{}"'.format(folder_path))

This will open the folder without any problems due to gaps in the path.
This is an excellent response, and I am quite appreciative of the fact that you choose to provide it.

Victor G.

Quote from:  . on February 23, 2024, 03:20:28 AM
Quote from:  . on April 14, 2023, 02:04:24 AM
Hi all,

Does anyone have any tricks to allow a folder to be opened (that contains spaces) with the os.Path.dirOpen method on a Windows client ?

Cheers

Dave

To open a folder with spaces using the os.Path.dirOpen function on a Windows client, wrap the folder path in double quotes. This ensures that the entire path is handled as a single item, with the spaces not construed as separators.
phrazle
For instance, if the folder location is "C:\Program Files", you can open it with the following code:

import os

folder_path = 'C:\\Program Files'
os.startfile('"{}"'.format(folder_path))

This will open the folder without any problems due to gaps in the path.
I will try, thanks.