import os
for root, dirs, files in os.walk("D:\BadFiles"):
for filename in files:
file_end = filename[-19:][:6]
print('INSERT INTO #TEMP(fileid) VALUES ('+str(int(file_end[:6]))+')')
I then created a temporary table in T-SQL and inserted the data :)