0

I need to open a file, found at C:/Users/HP Gold/Documents/My Program/Folder/Items.csv, in the default Windows application, which is for me, Libreoffice. I use the following command which I found on the web:

os.system("start " + directory+"/Items.csv")

However, I am getting an error when the line is run: "Windows cannot find the file "C:/Users/HP". Make sure you've typed the name correctly, then try again."

What must I do because this is obviously (I think) a problem with the segment "HP Gold" having a space.

badri
  • 438
  • 3
  • 11
xelab04
  • 15
  • 6
  • You probably need `"` around the directory: `os.system('start "' + directory + '/Items.csv"')` – tgikal May 12 '20 at 17:54
  • @tgikal Thanks, that actually did work. But, now, I'm getting a blank command screen box. The title of the window is the actual directory I'm aiming for but I now have the following in the command line: C:\Users\HP Gold\Documents\My Program>. Basically, the command didn't open the file but actually just opened a cmd tab. Maybe the command isn't the one I need. – xelab04 May 12 '20 at 18:02
  • 1
    I imagine you want to open the .csv file with some program `os.startfile(directory + '/Items.csv')` https://stackoverflow.com/questions/18173965/how-to-open-a-csv-file-in-microsoft-excel-in-python – tgikal May 12 '20 at 18:16
  • Use `os.startfile`. But FYI the issue with quoting is that CMD's `start` command consumes the first quoted string as the window title, so it should be used as `start "title" "command line to run"`. The title can be an empty string. – Eryk Sun May 12 '20 at 21:47
  • @tgikal Thanks very much. That solution works perfectly. Eryk Sun Not sure I understand the format of what the command should be. Anyways, it works now, so nevermind. Thanks so much anyways! – xelab04 May 13 '20 at 07:49

0 Answers0