PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 2, 2022

[FIXED] Why glob is not getting files in subfolders

 November 02, 2022     directory, file, python     No comments   

Issue

I have following directory structure

$ find
.
./file1.html
./soquest_glob.py

./dir1
./dir1/file2.html

./dir2
./dir2/file3.html

(I have added blank lines above to clarify files in different folders).

I am trying to find all html files (including those in subfolders) with following Python code using glob package:

$ cat soquest_glob.py

import glob
flist = glob.glob("*.html", recursive=True)
print(flist)

However, when I run this code, it finds only file in current folder, not in subfolders:

$ python3  soquest_glob.py
['file1.html']

Where is the problem and how can it be solved?


Solution

The recursive argument to glob.glob effects the behavior of **. You need to use a pattern like: glob.glob("**/*.html", recursive=True).



Answered By - DanielB
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing