Python Forum
How to handle paths with spaces in the name?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to handle paths with spaces in the name?
#1
I've been searching and still cannot find a solution to this issue. Under Windows 10, using Python 3.7, I'm passing a comma separated argument to the script, which then splits the string, and prints each file name. (Yes, the files need to be passed as one argument). But it doesn't work when spaces are in the path (See output below). How can I handle paths with spaces in the names?

jpgfiles = sys.argv[1]

for jpgfile in jpgfiles.split(','):
    print ("Processing %s " % jpgfile)
Output:
C:\Users\bernie\CentOS Share>myscript.py C:\Users\bernie\CentOS Share\DSC_1441.jpg,C:\Users\bernie\CentOS Share\DSC_1443.jpg Processing C:\Users\bernie\CentOS
Reply
#2
Put the list of jpg files in double quotes when you call the program from the command line.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pdf2image, poppler and paths jehoshua 18 14,517 Jun-14-2022, 06:38 AM
Last Post: jehoshua
  Windows paths issue otalado 3 1,454 May-29-2022, 09:11 AM
Last Post: snippsat
  automatically get absolute paths oclmedyb 1 2,107 Mar-11-2021, 04:31 PM
Last Post: deanhystad
  chkFile with absolute paths JarredAwesome 7 2,961 Sep-21-2020, 03:51 AM
Last Post: bowlofred
  Paths millpond 12 5,177 Jul-30-2020, 01:16 PM
Last Post: snippsat
  Problems with windows paths delphinis 6 5,153 Jul-21-2020, 06:11 PM
Last Post: Gribouillis
  Shortest paths to win snake and ladder sandaab 5 4,217 Jun-30-2019, 03:20 PM
Last Post: sandaab
  Question: Paths and writing to a file mwmaw 6 6,472 Dec-20-2016, 03:44 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020