Python Forum
dealing with spaces in file names
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dealing with spaces in file names
#6
(Jun-01-2018, 01:49 PM)snippsat Wrote:
(Jun-01-2018, 12:57 PM)AceScottie Wrote: I never actually define the string manually it's just pulled from os.listdir() so I can't add the r to the start of the string
os.listdir() just return filename,so why should you add r(raw string)?
If you build path yourself then can r or \\ or / just not singel \ because of escape charterer.
Maybe i misunderstand you,so it's better that you post code and explain what's not working.

Here using listdir and open in Notepad default Windows application.
Now i just working from current folder so no path is needed.
>>> import webbrowser
>>> import os
>>> 
>>> lst = os.listdir('.')
>>> lst
['c.py', 'cpt.py', 'f.py', 'html_env', 'path.py', 'test file.txt']
>>> webbrowser.open(lst[-1])
True 

Webbroweser is the best module i was looking for.
it fixes the file name issue and also opens the "open with" window for non associated files
Thansk
Reply


Messages In This Thread
dealing with spaces in file names - by AceScottie - May-31-2018, 10:09 PM
RE: dealing with spaces in file names - by snippsat - Jun-01-2018, 10:38 AM
RE: dealing with spaces in file names - by wavic - Jun-01-2018, 01:06 PM
RE: dealing with spaces in file names - by snippsat - Jun-01-2018, 01:49 PM
RE: dealing with spaces in file names - by AceScottie - Jun-02-2018, 01:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel from SAP - dealing with formats and VBA MasterOfDestr 7 590 Feb-25-2024, 12:23 PM
Last Post: Pedroski55
  rename same file names in different directories elnk 0 719 Nov-04-2022, 05:23 PM
Last Post: elnk
  UnicodeEncodeError - Dealing with Japanese Characters fioranosnake 2 2,495 Jul-07-2022, 08:43 PM
Last Post: fioranosnake
  Dealing with duplicated data in a CSV file bts001 10 11,577 Sep-06-2021, 12:11 AM
Last Post: SamHobbs
  Saving Excel workbook file with dataframe names Biplab1985 0 2,044 Jun-07-2020, 12:25 PM
Last Post: Biplab1985
  Dealing with a .json nightmare... ideas? t4keheart 10 4,415 Jan-28-2020, 10:12 PM
Last Post: t4keheart
  Details of attachment files in a msg file such as file names save into a python list klllmmm 2 5,726 Nov-12-2019, 05:59 AM
Last Post: klllmmm
  splitstring file names a by hyphen steve22020 3 3,299 Oct-30-2019, 05:39 PM
Last Post: steve22020
  Is there a more effecient way to do this ? File Names sumncguy 2 2,097 Jul-11-2019, 12:47 PM
Last Post: DeaD_EyE
  How to combine file names into a list from multiple directories? python_newbie09 3 5,223 Jul-09-2019, 07:38 PM
Last Post: python_newbie09

Forum Jump:

User Panel Messages

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