Explains how to get the file name containing the specified word (eg .htm) from the files in a certain folder.
This is the code to extract the files in the directory specified in filepath that include ".htm" in the file name.
test.py
import glob
filepath = 'C:/Users/fdfpy/work/yuho/stuck/XBRL/PublicDoc/'
files = glob.glob(filepath+'*.htm') #Get htm file
files = sorted(files) #Just sorting the files
print(files)
★★ Execution result ★★
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