Chris Macaluso
Chris Macaluso

Reputation: 1482

How to open a file with Python with white spaces in the name?

I have files that cannot be renamed without white spaces (work files). The file name is Evo PROG6001 FSJD0250240 E.PART stored in a variable file. If I run os.system('start ' "'" + file + "'") it only recognizes the word Evo and returns Windows cannot find "Evo". Make sure you types the name correctly, and then try again. The same thing occurs with os.system('start ' + file).

Is there a way to do this?

Upvotes: 0

Views: 1377

Answers (1)

Chris Macaluso
Chris Macaluso

Reputation: 1482

I needed to use os.startfile() and also point it to the root directory, which I had stored previously.

os.startfile(new_folder + '\\' + file) works

Upvotes: 2

Related Questions