2

When i download my file on Microsoft Forms the file comes with the name: 'C:/Downloads/form(1-219).xlsx'

But for each answer that form receive, the name of the file changes for example, now is: 'C:/Downloads/form(1-230).xlsx'

Always the number of answers is the number that will appear at the end of the file

is there any way python can read this file?

Thank your for the help.

  • Sounds like something [`glob.glob()`](https://docs.python.org/3/library/glob.html#glob.glob) could be used for. – Hampus Larsson Jul 23 '20 at 20:50
  • [This would probably answer your question](https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory) – RakeshV Jul 23 '20 at 20:54

1 Answers1

1
  1. Use glob to read in the filenames with the defined pattern into a list l, putting a * at the point where the filename becomes dynamic. Then, use [-1] to only return the last filename with that list of filenames to the variable f.
  2. Finally, simply read in the file itself:

code:

import glob
f = glob.glob(f'C:/Downloads/form(1-*.xlsx')[-1]
df = pd.read_excel(f)
df
David Erickson
  • 16,433
  • 2
  • 19
  • 35