Using path extension \\?\ for windows 7 with python script
<p>I'm using the tool <a href="https://github.com/NavicoOS/ac2git" rel="nofollow">ac2git</a> to convert my Accurev depot to git repository. I'm facing a problem when the os.walk() function in the python file runs. Since my project has a pretty complicated build path I have nested files that have path length exceeding the 260 limitation on Windows 7.I tried using the work-arounds provided by <a href="https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath" rel="nofollow">microsoft support</a> but it is not resolving the error. I still get the error [Winerror 3]: File not found , when in fact it is present but cannot be accessed due to the length limitation.</p>

<p>This is a part of the code in the ac2git.py script:</p>

<pre><code>def PreserveEmptyDirs(self):
    preservedDirs = []
    for root, dirs, files in os.walk(self.gitRepo.path, topdown=True):
        for name in dirs:

            path ="\\\\?\\"+ToUnixPath(os.path.join(root, name))


            # Preserve empty directories that are not under the .git/ directory.
            if git.GetGitDirPrefix(path) is None and len(os.listdir(path)) == 0:
                filename = os.path.join(path, '.gitignore')
                with codecs.open(filename, 'w', 'utf-8') as file:
                    #file.write('# accurev2git.py preserve empty dirs\n')
                    preservedDirs.append(filename)
                if not os.path.exists(filename):
                    logger.error("Failed to preserve directory. Couldn't create '{0}'.".format(filename))
    return preservedDirs


def ToUnixPath(path):
rv = SplitPath(path)
if rv is not None:
    if rv[0] == '/':
        rv = '/' + '/'.join(rv[1:])
    else:
        rv = '/'.join(rv)
return rv

def SplitPath(path):
rv = None
if path is not None:
    path = str(path)
    rv = []
    drive, path = os.path.splitdrive(path)
    head, tail = os.path.split(path)
    while len(head) &gt; 0 and head != '/' and head != '\\': # For an absolute path the starting slash isn't removed from head.
        rv.append(tail)
        head, tail = os.path.split(head)
    if len(tail) &gt; 0:
        rv.append(tail)
    if len(head) &gt; 0: # For absolute paths.
        rv.append(head)
    if len(drive) &gt; 0:
        rv.append(drive)
    rv.reverse()
return rv
</code></pre>

<p>I have appended the "\\?\" in order to allow for longer path lengths but now I get this error:</p>

<pre><code>FileNotFoundError: [WinError 3] The system cannot find the path specified: '\\\\?\\C:///s/cms'
</code></pre>

<p>I'm new to Python and I'm not very sure what is the right approach to tackle it. I have to continue using Windows 7 only. Any suggestions if this problem can be fixed another way?</p>

<p>So after much ado, I made changes in the python code, </p>

<p>Apparently this information is very important " <em>File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\?\" prefix as detailed in the following sections.</em>"</p>

<p>So I just added this code to the function:</p>

<pre><code>def ToUnixPath(path):
rv = SplitPath(path)
rv[:] = [item for item in rv if item != '/']
     rv = '\\'.join(rv)
     return r"\\?"+"\\"+rv
</code></pre>

<p>And it worked!</p>

python git windows-7-x64 accurev