0

I am using osin Python to retrieve a list of files in a folder. Once I get the list, I want to clean up the names of the files and remove the ".pdf" at the end of each file name. What I'm trying, is not working.

    path = "C:/....."
    dirs = os.listdir(path)
    dirs = pd.DataFrame(data=dirs)
    dirs.replace({".pdf", None}, inplace=True)
    print(dirs, sep="\n")

These are an example of the files in my folder enter image description here So basically, I only want to keep the digits of the filename.

DeAnna
  • 404
  • 6
  • 17

1 Answers1

1

You can use os.path.splitext().

dirs = os.path.splitext("/path/to/some/file.pdf")[0])

This results in:

/path/to/some/file
Jonas
  • 1,749
  • 1
  • 10
  • 18