简体   繁体   中英

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 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM