Accessing Uploaded Files without Writing the Filename

Hi! I was wondering if it is possible to access a file uploaded to Replit (e.g. a CSV file without having to manually change the name of the file in the Python code every time? I will be uploading many different files to this code and it is not very efficient to change the file name within the code every time I run it.

Here is an example of how I am connecting my code to the files I have uploaded:

file1 = 'NBA FD Projections (1).csv'
file2 = 'projections_fanduel_nba_96446.csv'
output_file = 'combined_output.csv'

Hi @MirandaParrish1 , welcome to the forums!
You mean opening/reading a file with the file path stored in a variable?

1 Like

Yes, that’s what I mean! I was hoping if there’s another possible way to access the files, such as iterating through all the uploaded files and searching for files that start with a specific set of characters. Any suggestions would be great!

@MirandaParrish1 I see what you mean.
Maybe try doing this:

import os
for file in os.listdir():
  if file.startswith('.'): # Use the startswith() function
    print(file)

This loops through all the files and folders in the base directory, then printing those files that start with a specific something.
Hope this helps!

2 Likes