Explique comment obtenir le nom d'un fichier contenant un mot spécifié (par exemple .htm) à partir d'un fichier dans un dossier.
Code pour extraire les fichiers dans le répertoire spécifié dans filepath qui incluent ".htm" dans le nom de fichier.
test.py
import glob
filepath = 'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc/'
files = glob.glob(filepath+'*.htm') #Obtenir le fichier htm
files = sorted(files) #Juste trier les fichiers
print(files)
★★ Résultat de l'exécution ★★
python
['C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0000000_header_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0101010_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0102010_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0103010_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm', 'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0104010_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105000_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105010_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105020_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105025_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105040_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm', 'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105050_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105100_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105110_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm', 'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105310_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105320_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105330_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm', 'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105400_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0105410_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0106010_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm', 'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0107010_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm',
'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc\\0201010_honbun_jpcrp030000-asr-001_E02995-000_2019-08-20_01_2019-11-08_ixbrl.htm']
Recommended Posts