Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28877

Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py

Date 2012-09-11 08:20 +0100
From Tim Golden <mail@timgolden.me.uk>
Subject Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py
References <a4a2e63b-d25d-4487-bff8-67d4b7c40cbc@googlegroups.com> <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.489.1347348083.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 11/09/2012 04:46, Steven D'Aprano wrote:
> On Mon, 10 Sep 2012 15:22:05 -0700, ruck wrote:
> 
>> On Monday, September 10, 2012 1:16:13 PM UTC-7, Steven D'Aprano wrote:
> [...]
>>> That's not so much a workaround as the officially supported API for
>>> dealing with the situation you are in. Why don't you just prepend a 
>>> '?' to paths like they tell you to?
>>
>> Good idea, but the first thing os.walk() does is a listdir(), and
>> os.listdir() does not like the r'\\?\' prefix.  In other words,
>> os.walk(r'\\?\C:Users\john\Desktop\sandbox\goo') does not work.
> 
> Now that sounds like a bug to me. If Microsoft officially support 
> leading ? in file names, then so should Python on Windows.

And so it does, but you'll notice from the MSDN docs that the \\?
syntax must be supplied as a Unicode string, which os.listdir
will do if you pass it a Python unicode object and not otherwise:

import os
os.listdir(u"\\\\?\\c:\\users")

# and consequently

for p, ds, fs in os.walk(u"\\\\?\\c:\\users"):
  print p


TJG

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py ruck <john.ruckstuhl@gmail.com> - 2012-09-10 10:25 -0700
  Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-10 20:16 +0000
    Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py ruck <john.ruckstuhl@gmail.com> - 2012-09-10 15:22 -0700
      Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-11 03:46 +0000
        Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Tim Golden <mail@timgolden.me.uk> - 2012-09-11 08:20 +0100
          Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py ruck <john.ruckstuhl@gmail.com> - 2012-09-11 12:13 -0700
            Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Chris Angelico <rosuav@gmail.com> - 2012-09-12 08:50 +1000
            Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Dave Angel <d@davea.name> - 2012-09-11 18:57 -0400
          Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py ruck <john.ruckstuhl@gmail.com> - 2012-09-11 12:13 -0700
        Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-12 08:17 +0200
          Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py aahz@pythoncraft.com (Aahz) - 2012-11-09 16:42 -0800

csiph-web