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

  • Home
  • SEARCH
  • 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 8473483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:21:50+00:00 2026-06-10T17:21:50+00:00

The problem is the character limit for the path in windows when creating multiple

  • 0

The problem is the character limit for the path in windows when creating multiple directories using pythons os.makedirs()

I found this post when searching for my problem before posting this:

python win32 filename length workaround

Now the chosen answer suggests the prefix workaround but my question here is, is there a way to ensure functionality in Windows and UNIX?

The other approach I thought of was to create the folders one by one and then create the file so that you never exceed the path length, but I can’t figure out the obvious bug in the code.

path = ['folder1/s1/s1/abc.txt',
        'folder1/s1/s2/def.txt']

def makedirs(path):
    explode = path.split('/')
    for i in range(len(explode)-1):
        os.mkdir(explode[i])
        os.chdir(explode[i])

        if i == len(explode) -2:
            download_file(explode[i+1])

    # something to go back here
    os.chdir('../' * (len(explode)-3)) # ??


makedirs(path[0])

Now this works for only the first line because I can’t figure out how to get back to the root or reset it. Without the ‘reset’ the folders are being under each other:

folder1/s1/s1/folder1/s1/s1/abc.txt (or something like that)

I could set the path from root to reset it but then we might run into the same issue of reaching the max length. Any help on how to get this working on both OS would be appreciated!

Please feel free to point out where I’m wrong.

  • 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-06-10T17:21:52+00:00Added an answer on June 10, 2026 at 5:21 pm

    Per this stackoverflow answer: while chdir can go up one directory with os.chdir(“..”), the platform-agnostic way is: os.chdir(os.pardir).

    Either call this N times in a loop;
    or try an unreadable one-liner like this (untested):
    os.chdir(os.path.join(*([os.pardir] * NUM_TIMES)))

    (Instead of path.split(‘/’), you could also use the method described here for it to work on all operating systems)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JSLint is giving me this error: Problem at line 11 character 33: Use the
I need to enforce character count limit in my application. I found some JavaScripts
I want to make timer string with CCLabelAtlas. The problem is the character, :.
Simple problem that I can't figure out... How can I print a '%' character
I'm attempting to remove a character from a string in C. The problem I
I am using TortiseSVN and we have a problem when we exporting etc because
I have a problem to draw a square ASCII with the size limit in
There is a string, which comes from text field, and has 200 character limit.
I want to limit the character users can type in iPhone's keyboard, so I
The problem: Limit allowed characters in a HTML input to a-z A-Z only. For

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.