Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2a.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; 'source.': 0.05; 'escape': 0.07; 'subject:file': 0.07; 'chime': 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; 'output': 0.15; 'argument.': 0.16; 'command;': 0.16; 'instead:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:folder': 0.16; 'subject:sub': 0.16; 'subprocess': 0.16; 'wildcards': 0.16; 'wrote:': 0.16; 'directory.': 0.18; 'shell': 0.18; 'windows': 0.20; 'skip:" 30': 0.20; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'subject:/': 0.29; 'looks': 0.29; 'invoke': 0.29; 'quiet': 0.29; 'too.': 0.30; 'skip:s 30': 0.31; 'probably': 0.32; "d'aprano": 0.33; 'steven': 0.33; 'this?': 0.34; 'to:addr:python-list': 0.35; 'ahead': 0.35; 'path': 0.35; 'but': 0.36; 'too': 0.36; 'should': 0.37; 'subject:: ': 0.37; 'instead': 0.38; 'received:org': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'subject:-': 0.39; 'received:de': 0.40; 'back': 0.61; 'confirm': 0.61; 'avoid': 0.61; 'skip:u 10': 0.62; 'expert': 0.63; 'experts': 0.67; 'believe': 0.67; 'day': 0.70; '3.4': 0.84; 'actually,': 0.84; 'safer': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence Date: Thu, 21 May 2015 10:54:36 +0200 Organization: None References: <9d786d0b-0f25-4446-a730-ff1fe2f6b20d@googlegroups.com> <555d9233$0$12913$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd9018.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432198490 news.xs4all.nl 2952 [2001:888:2000:d::a6]:54213 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91003 Steven D'Aprano wrote: > Also, this only looks in the C:.../XYZ directory. I think that Python 3.4 > or better will accept a ** wildcard instead of * to look in subdirectories > too. Unfortunately that's Python 3.5. You are ahead of time. > Actually, I think you don't need the shell argument. Try this instead: > > path = "c:/abc/def/ghj/main/features/XYZ/*" + str(tempID) + ".cli" > output = subprocess.check_output(['dir', '/s', '/b', path]) "dir" used to be an internal command; back in the day you would have to invoke it with (untested) check_output(["cmd", "/k", 'dir', '/s', '/b', path]) I believe on Windows path may contain wildcards -- or does subprocess escape these somehow? > That is likely to be safer and will help avoid shell injection attacks if > the path comes from an untrusted source. Any subprocess experts want to > confirm this? I probably should have kept quiet to let a combined subprocess/windows expert chime in -- but now it's too late...