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 8894057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:24:06+00:00 2026-06-14T23:24:06+00:00

I am running my python code on Windows and trying to traverse and store

  • 0

I am running my python code on Windows and trying to traverse and store all the file name with their paths in a file. But the Windows has a restriction of 260 characters.

os.chdir(self.config.Root_Directory_Path())        
    for root, dirs, files in os.walk("."):
        file_list.extend( join(root,f) for f in files )
    file_name_sorted = sorted(file_list)
    #file_sorted = sorted(file_list, key=getsize)
    #time.strftime("%m/%d/%Y %I:%M:%S %p" ,time.localtime(os.path.getmtime(file)))
    f = open(self.config.Client_Local_Status(),'wb')        
    for file_name in file_name_sorted:
        if (os.path.exists(file_name)):
            #f.write((str(os.path.getmtime(file_name)) + "|" + file_name + "\n").encode('utf-8'))
            pass
        else:
            print(file_name + "|" + str(len(file_name) + len(originalPath)) + "\n")
            print(os.path.getmtime(file_name))
            #f.write((str(os.path.getmtime(file_name)) + "|" + file_name + "\n").encode('utf-8'))
    f.close()

Because of the error, os.path.getmtime(file_name) throws an exception file not found. How can I overcome this problem? I tried using //?/ character as prefix, as suggested in

http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx

But was not successful in using //?/ character.

I tried using os.path.getmtime(“////?//” + file_name) #Threw an error invalid path

Please suggest a fix

  • 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-14T23:24:07+00:00Added an answer on June 14, 2026 at 11:24 pm

    The problem here is that you’re using a relative path. The \\?\ prefix can only be applied to absolute paths. As the documentation says:

    These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory. Because you cannot use the “\\?\” prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters.

    The fix is simple. Instead of this:

    '\\\\?\\' + file_name
    

    do this:

    '\\\\?\\' + os.path.abspath(file_name)
    

    You cannot use forward slashes. It may or may not be legal to add an extra backslash, in which case you can get away with r'\\?\\' instead of doubling the double backslash. Try it and see (but make sure to test both drive-prefixed paths like C:\foo and UNC paths like \\server\share\bar)… But the doubled-backslash version above should definitely work.

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

Sidebar

Related Questions

I tried running the following python code in Eclipse on Windows but it is
I'm trying to use pygtk in Python but when I try running my code
I'm running Python 2.5.4 on Windows and I keep getting an error when trying
I am running python on windows and trying to pretty print a json output.
On Windows 7, running Python 2.7, python setup.py install installs python-money , but doesn't
I'm running some python code for the first time on a Windows 7 machine
I'm trying to convert this VBScript code to Python (Win32) code but with no
When running the following python code: >>> f = open(rmyfile.txt, a+) >>> f.seek(-1,2) >>>
I'm running Ubuntu to compile a set of code which requires python 2.4. How
I'm writing some code which involves running a few shell commands from Python and

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.