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


Groups > comp.lang.python > #91003

Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence

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 2015-05-21 10:54 +0200
Organization None
References <9d786d0b-0f25-4446-a730-ff1fe2f6b20d@googlegroups.com> <555d9233$0$12913$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.195.1432198490.17265.python-list@python.org> (permalink)

Show all headers | View raw


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...

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


Thread

Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence chaotic.sid@gmail.com - 2015-05-20 22:34 -0700
  Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-21 18:07 +1000
    Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence Peter Otten <__peter__@web.de> - 2015-05-21 10:54 +0200
    Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence Tim Golden <mail@timgolden.me.uk> - 2015-05-21 10:06 +0100
    Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence Grant Edwards <invalid@invalid.invalid> - 2015-05-21 14:14 +0000
      Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence Chris Angelico <rosuav@gmail.com> - 2015-05-22 00:27 +1000
        Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence Grant Edwards <invalid@invalid.invalid> - 2015-05-21 16:31 +0000
          Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence MRAB <python@mrabarnett.plus.com> - 2015-05-21 17:54 +0100
      Re: Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence Tim Golden <mail@timgolden.me.uk> - 2015-05-21 15:32 +0100

csiph-web