简体   繁体   中英

glob.glob doesn't return any result

I don't know what is wrong with my code. When I changed a location of file it works. But when I come to the folder which I need I didn't get any results. I checked the location, searched for specific png file as ( '*/*.png' ), the result is same. Could you please advise me, what can cause to this.

import os, glob
file_path = "/Users/XXXX/Desktop/png"
my_png_path = os.path.join(file_path, '*/*')
for my_files in glob.glob(my_png_path):
   print(my_files)

Base on

file_path = "/Users/XXXX/Desktop/png"
my_png_path = os.path.join(file_path, '*/*')

The value of my_png_path is sth. like /Users/XXXX/Desktop/png/*/* , but I guess your intention is /Users/XXXX/Desktop/*/*.png , so the code should like

file_path = "/Users/XXXX/Desktop"
my_png_path = os.path.join(file_path, '*/*.png')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM