Python Forum
Printing a raw string with a folder separator at the end, duplicates the separator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing a raw string with a folder separator at the end, duplicates the separator
#3
Dear rob101, thank you for the suggestion. First, I would have to check, whether slicing makes sense, i.e, Is there a double backslash at the end of the string? The input of the directory may come from the user and it cannot be predected.

I can replace using a regex
print(re.sub(r"(?<=[\\])(\\)", r"", r"dir1\dir2\\dir3\\\dir4\\\\"))
and end up with an expected:
Output:
dir1\dir2\dir3\dir4\
I understand that it is a cosmetic issue. The operating system is going to collapse multiple backslashes into a single one, or ignore the superfluous. The script works anyway.
Reply


Messages In This Thread
RE: Printing a raw string with a folder separator at the end, duplicates the separator - by krulah - Nov-28-2022, 11:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  coma separator is printed on a new line for some reason tester_V 4 1,407 Feb-02-2024, 06:06 PM
Last Post: tester_V
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 1,464 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  remove partial duplicates from csv ledgreve 0 1,627 Dec-12-2022, 04:21 PM
Last Post: ledgreve
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 6,276 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  printing a string in reverse Skaperen 2 2,166 Nov-20-2021, 05:08 AM
Last Post: ghoul
  printing an string instead of a expression Underscore 2 2,562 Oct-11-2021, 03:10 PM
Last Post: deanhystad
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 3,109 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  Removal of duplicates teebee891 1 2,398 Feb-01-2021, 12:06 PM
Last Post: jefsummers
  Displaying duplicates in dictionary lokesh 2 2,727 Oct-15-2020, 08:07 AM
Last Post: DeaD_EyE
  Printing string at specific position on terminal - not showing __Mathieu__ 1 3,370 Sep-07-2020, 10:32 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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