Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6992543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:38:53+00:00 2026-05-27T19:38:53+00:00

I have a text file containing the output of a recursive directory listing that

  • 0

I have a text file containing the output of a recursive directory listing that generally looks like this:

./subfolder/something with spaces:
something\ with\ spaces.txt*
something\ with\ spaces.dat*

./subfolder/yet another thing:
yet\ another\ thing.txt*
yet\ another\ thing.dat*

I need to get a list of the full paths to each .txt file:

./subfolder/something with spaces/something with spaces.txt
./subfolder/yet another thing/yet another thing.txt

I’ve almost got a solution for this, but what’s the best solution for unescaping the filenames in Python? I don’t know exactly what characters ls -R escaped (space and = are two such characters, though). I don’t have access to the drive containing these files, either, so using a better command to obtain the list is out of the question, unfortunately.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:38:54+00:00Added an answer on May 27, 2026 at 7:38 pm

    I’m not sure if there’s built-in for this, but a simple regex could be used.

    re.sub(r'(?<!\\)\\', '', filename)
    

    This would remove all backslashes (except for those following another backslash). This seems to be the behavior when you try and echo these values on the terminal (I’ve only tested this in bash).

    bash-3.2$ echo foo\\bar
    foo\bar
    bash-3.2$ echo foo\ bar
    foo bar
    bash-3.2$ echo foo\=bar
    foo=bar
    

    Here’s a complete python example:

    import re
    
    def unescape(filename):
        return re.sub(r'(?<!\\)\\', '', filename)
    
    print unescape(r'foo\ bar')
    print unescape(r'foo\=bar')
    print unescape(r'foo\\bar')
    

    Output:

    foo bar
    foo=bar
    foo\bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file containing words separated by newline , like the following
I have to filter a text file filter.tmp containing two types of lines, this
I have a big text file containing data that needs to be extracted and
Suppose I have a tab delimited file containing user activity data formatted like this:
I have a CSV file like this: text,0 more text,2 some more text,100 I
I have a model that looks like this: class Pdf extends \lithium\data\Model { protected
I have a text file containing strings to encrypt. These strings are indicated by
I have a text file containing 5 columns of data. The first column contains
I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a text file containing unwanted null characters (ASCII NUL, \0 ). When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.