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.

5
  • You probably need " around the directory: os.system('start "' + directory + '/Items.csv"') Commented May 12, 2020 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. Commented May 12, 2020 at 18:02
  • 1
    I imagine you want to open the .csv file with some program os.startfile(directory + '/Items.csv') stackoverflow.com/questions/18173965/… Commented May 12, 2020 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. Commented May 12, 2020 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! Commented May 13, 2020 at 7:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.