Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Windows': 0.02; 'explicitly': 0.05; 'abuse': 0.07; 'args': 0.07; 'if,': 0.09; 'preferable': 0.09; 'spaces': 0.09; 'things,': 0.09; 'contribute': 0.11; 'itself.': 0.14; "'+'": 0.16; "';'": 0.16; '*must*': 0.16; 'columns': 0.16; 'command,': 0.16; 'example)': 0.16; 'goal,': 0.16; 'invocation': 0.16; 'observations': 0.16; 'say.': 0.16; 'simplest': 0.16; 'stuff.': 0.16; 'subject:Unicode': 0.16; 'syntax,': 0.16; 'wished': 0.16; 'files.': 0.16; 'wrote:': 0.18; '(not': 0.18; '(the': 0.22; 'command': 0.22; '>>>': 0.22; 'example': 0.22; 'shell': 0.22; 'to:name:python-list@python.org': 0.22; "aren't": 0.24; 'expanded': 0.24; 'cheers,': 0.24; 'file.': 0.24; 'looks': 0.24; 'equivalent': 0.26; 'task': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'appear': 0.29; 'chris': 0.29; 'feature': 0.29; 'am,': 0.29; 'points': 0.29; 'expansion': 0.30; 'involving': 0.30; 'matching': 0.30; 'message- id:@mail.gmail.com': 0.30; 'getting': 0.31; 'end,': 0.31; 'equivalent.': 0.31; 'invoke': 0.31; 'operations.': 0.31; 'terminate': 0.31; 'anyone': 0.31; 'quite': 0.32; 'are:': 0.33; 'fri,': 0.33; "can't": 0.35; 'info': 0.35; 'display': 0.35; 'common': 0.35; 'except': 0.35; 'possible.': 0.35; 'tool': 0.35; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'like,': 0.36; 'done': 0.36; 'next': 0.36; 'thanks': 0.36; 'example,': 0.37; 'two': 0.37; 'list': 0.37; 'system,': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'issue': 0.38; 'skip:- 10': 0.38; 'that,': 0.38; 'anything': 0.39; 'does': 0.39; 'extremely': 0.39; 'to:addr:python.org': 0.39; 'system.': 0.39; 'even': 0.60; 'truly': 0.60; 'length': 0.61; 'simply': 0.61; 'first': 0.61; 'such': 0.63; 'maximum': 0.63; 'interest': 0.64; 'more': 0.64; 'chance': 0.65; '(that': 0.65; 'within': 0.65; 'believe': 0.68; 'results': 0.69; 'bulk': 0.74; 'special': 0.74; 'potentially': 0.81; 'exceeding': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=z9KWtJYrG9GfUUk86TDhkWUbpaAOqnGOY240vuFroeE=; b=inoLqzD9q+6P0NhlCwtgN3iDBmCtWPhwskQL3lbxo49q9uC7d9ToS7+VvXpq+v3Hqn KluMJUvt5FJEaYmP7UFp9gTbf1YnQNcAygQhdUZe3bfdSHZc3bgS7/M+nLFXD48Y8465 uvLevdFhbQmyvyLsXoDwJlTYa4o6eQk6HiUBSKv47uDnNxHf4RnFmZFaa0lzPszvqHby QbsSn70FWv+kl/GdNM9VKoV+D42+aZz5H62ux1lj21sd+v3i+st2Gb9dEKJFAPWhmKLE uJyNPTfZ1lQlwEC6dG8VmojQpIDHyUcihtJSjoFx6P0SXn6j08x68RcWvUDhuyKDpqTk bz/A== MIME-Version: 1.0 X-Received: by 10.58.202.133 with SMTP id ki5mr2499967vec.19.1396576960860; Thu, 03 Apr 2014 19:02:40 -0700 (PDT) In-Reply-To: References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> <87fvluss86.fsf@elektro.pacujo.net> <1396533471.32018.102326165.14B5BB43@webmail.messagingengine.com> Date: Fri, 4 Apr 2014 13:02:40 +1100 Subject: Re: Unicode Chars in Windows Path From: David To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 84 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396576970 news.xs4all.nl 2904 [2001:888:2000:d::a6]:39215 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69629 On 4 April 2014 12:16, Chris Angelico wrote: > On Fri, Apr 4, 2014 at 11:15 AM, David wrote: >> On 4 April 2014 01:17, Chris Angelico wrote: >>> >>> -- Get info on all .pyc files in a directory and all its subdirectories -- >>> C:\>dir some_directory\*.pyc /s >>> $ ls -l `find some_directory -name \*.pyc` >>> >>> Except that the ls version there can't handle names with spaces in >>> them, so you need to faff around with null termination and stuff. >> >> Nooo, that stinks! There's no need to abuse 'find' like that, unless >> the version you have is truly ancient. Null termination is only >> necessary to pass 'find' results *via the shell*. Instead, ask 'find' >> to invoke the task itself. >> >> The simplest way is: >> >> find some_directory -name '*.pyc' -ls >> >> 'find' is the tool to use for *finding* things, not 'ls', which is >> intended for terminal display of directory information. > > I used ls only as a first example, and then picked up an extremely > common next example (deleting files). It so happens that find can > '-delete' its found files, but my point is that on DOS/Windows, every > command has to explicitly support subdirectories. If, instead, the > 'find' command has to explicitly support everything you might want to > do to files, that's even worse! So we need an execution form... > >> If you require a particular feature of 'ls', or any other command, you >> can ask 'find' to invoke it directly (not via a shell): >> >> find some_directory -name '*.pyc' -exec ls -l {} \; > > ... which this looks like, but it's not equivalent. > That will execute > 'ls -l' once for each file. You can tell, because the columns aren't > aligned; for anything more complicated than simply 'ls -l', you > potentially destroy any chance at bulk operations. Thanks for elaborating that point. But still ... > equivalent it *must* pass all the args to a single invocation of the > program. You need to instead use xargs if you want it to be > equivalent, and it's now getting to be quite an incantation: > > find some_directory -name \*.pyc -print0|xargs -0 ls -l > > And *that* is equivalent to the original, but it's way *way* longer > and less convenient, which was my point. If you are not already aware, it might interest you that 'find' in (GNU findutils) 4.4.2. has -- Action: -execdir command {} + This works as for `-execdir command ;', except that the `{}' at the end of the command is expanded to a list of names of matching files. This expansion is done in such a way as to avoid exceeding the maximum command line length available on the system. Only one `{}' is allowed within the command, and it must appear at the end, immediately before the `+'. A `+' appearing in any position other than immediately after `{}' is not considered to be special (that is, it does not terminate the command). I believe that achieves the goal, without involving the shell. It also has an -exec equivalent that works the same but has an unrelated security issue and not recommended. But if that '+' instead of ';' feature is not available on the target system, then as far as I am aware it would be necessary to use xargs as you say. Anyway, the two points I wished to contribute are: 1) It is preferable to avoid shell command substitutions (the backticks in the first example) and expansions where possible. 2) My observations on 'find' syntax, for anyone interested. Cheers, David