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


Groups > comp.lang.python > #93202

Re: windows and file names > 256 bytes

X-FeedAbuse http://nntpfeed.proxad.net/abuse.pl feeded by 195.154.70.45
Path csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'string.': 0.04; 'paths': 0.05; 'sys': 0.05; 'default.': 0.07; 'shutil': 0.07; 'subject:file': 0.07; 'welcome.': 0.07; 'wrapper': 0.07; '"w")': 0.09; 'below).': 0.09; 'mentions': 0.09; 'messing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'skip:# 20': 0.13; ':-)': 0.14; 'def': 0.14; 'skip:p 40': 0.15; 'thu,': 0.15; '(and,': 0.16; 'paths.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:windows': 0.16; 'subst,': 0.16; 'tmpdir': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'tree': 0.18; '>>>': 0.20; 'all,': 0.20; 'windows': 0.20; '(see': 0.20; 'software.': 0.22; '3.x': 0.22; 'am,': 0.23; 'bit': 0.23; '2015': 0.23; 'absolute': 0.23; 'errors': 0.23; 'passing': 0.23; "i've": 0.24; 'tried': 0.24; 'import': 0.24; 'somewhere': 0.24; 'tim': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'possibility': 0.27; 'dos': 0.27; 'function:': 0.29; 'skip:u 20': 0.30; '---': 0.30; 'work.': 0.30; 'certainly': 0.31; 'print': 0.31; 'checked': 0.31; 'post': 0.32; 'probably': 0.32; 'michael': 0.33; "he's": 0.33; 'changing': 0.34; 'file': 0.34; 'could': 0.35; 'to:addr:python-list': 0.35; 'dir': 0.35; 'path': 0.35; 'somebody': 0.35; 'unicode': 0.35; 'problem.': 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'created': 0.36; 'there': 0.36; 'thanks': 0.36; 'possible': 0.36; 'subject:: ': 0.37; 'delete': 0.37; 'received:org': 0.38; 'feedback': 0.38; 'names': 0.38; 'test': 0.39; 'to:addr:python.org': 0.39; 'seem': 0.39; 'where': 0.40; 'him': 0.60; 'your': 0.60; 'even': 0.61; 'more.': 0.62; 'more': 0.62; 'goal': 0.64; 'antivirus': 0.66; 'finally': 0.70; 'received:nl': 0.72; 'sounds': 0.72; 'special': 0.72; '2.7.': 0.84; 'actually,': 0.84; 'avast': 0.84; 'pain': 0.84; 'replies.': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Albert-Jan Roskam <sjeik_appie@hotmail.com>
Subject Re: windows and file names > 256 bytes
Date Fri, 26 Jun 2015 17:48:54 +0000 (UTC)
References <mmgce2$cd4$1@ger.gmane.org> <mmgnbt$u0o$1@ger.gmane.org> <CAB1GNpS=7F3ebrHenUu7+MvyWuk5v60G6N6L81c0W3C-mQPi2w@mail.gmail.com> <558BF55C.2010701@timgolden.me.uk> <558C038A.5010103@gmail.com> <558C0433.2050601@timgolden.me.uk>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host 82-170-182-209.ip.telfort.nl
User-Agent Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
X-Antivirus avast! (VPS 150624-2, 06/24/2015), Outbound message
X-Antivirus-Status Clean
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.109.1435340943.3674.python-list@python.org> (permalink)
Lines 76
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1435340943 news.xs4all.nl 2917 [2001:888:2000:d::a6]:45683
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:93202

Show key headers only | View raw


On Thu, 25 Jun 2015 14:37:55 +0100, Tim Golden wrote:

> On 25/06/2015 14:35, Michael Torrie wrote:
>> On 06/25/2015 06:34 AM, Tim Golden wrote:
>>> On 25/06/2015 13:04, Joonas Liik wrote:
>>>> It sounds to me more like it is possible to use long file names on
>>>> windows but it is a pain and in python, on windows it is basically
>>>> impossible.
>>>
>>> Certainly not impossible: you could write your own wrapper function:
>>>
>>> def extended_path(p):
>>>     return r"\\?\%s" % os.path.abspath(p)
>>>
>>> where you knew that there was a possibility of long paths and that an
>>> absolute path would work.
>> 
>> The OP mentions that even when he manually supplies extended paths,
>> os.mkdir, os.getsize, and shutil.rmtree return errors for him in Python
>> 2.7.  So there's more to this problem.
>> 
>> 
> He's probably not passing unicode strings: the extended path only works
> for unicode string. For 3.x that's what you do by default.

Hi all,

Thanks for your replies. I've been messing with this a bit more. I 
created a little test script (see below). However, this only works with 
drive letters, not with UNC paths. I tried using os.chdir, DOS pushd, 
subst, net use but they all don't seem to work with with looooong paths. 
I finally managed to remove an absurdly long dir with shutil.rmtree, 
after changing sys.setrecursionlimit. But my main goal was to get the 
file size (and, actually, also the file owner) of a long file name on XP.

import os
import shutil
import sys
 
# create an insanely long directory tree
p = os.getenv("TEMP")
#p = ur"\\server\share\blah\temp"
tmpdir = p
os.chdir(tmpdir)
for i in xrange(1000):
    tmpdir = os.path.join(tmpdir, "sub")
    os.mkdir("\\\\?\\" + tmpdir)
    #os.mkdir(u"\\\\?\\UNC" + tmpdir[1:])
 
# write a file to it
deep = "\\\\?\\" + os.path.join(tmpdir, "deep.txt")
assert os.path.exists(deep)
with open(deep, "w") as f:
    f.write("Deep!\r\n")
 
# try if the file size can be determined (requires special \\?\ notation)
print "@@@@ %d bytes" % os.path.getsize(deep)
 
# now delete the whole directory and its contents.
path = "\\\\?\\" + os.path.join(p, "sub")
path = path.decode(sys.getfilesystemencoding())
sys.setrecursionlimit(10 ** 7)  # net use, pushd, subst will not work
shutil.rmtree(path)

Any feedback is welcome. I will post the solution somewhere so somebody 
else will be spared this nuisance. :-)

Regards,
Albert-Jan


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Thread

Re: windows and file names > 256 bytes Albert-Jan Roskam <sjeik_appie@hotmail.com> - 2015-06-26 17:48 +0000

csiph-web