0

I want to get only the real path of the file selected without quotes and without the file extension

def newCall(self):
        global rfile
        rfile = QFileDialog.getOpenFileName(self, "Sélectionner une vidéo", "", "Video Files (*.mp4)")
        self.lineEntry.setText(str(rfile))
        print('Selected:', rfile)

When I run the code I will get this

Selected: ('C:/Users/user/Desktop/segmentation/comfort.mp4', 'Video Files (*.mp4)')

I need only this path

C:/Users/user/Desktop/segmentation/comfort.mp4
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Abdelmelek
  • 19
  • 1
  • 2
    change `rfile = QFileDialog.getOpenFileName(self, "Sélectionner une vidéo", "", "Video Files (*.mp4)")` to `rfile, ok = QFileDialog.getOpenFileName(self, "Sélectionner une vidéo", "", "Video Files (*.mp4)")` – S. Nick Jul 14 '20 at 13:36

1 Answers1

0

Select the first element in rfile (which is a tuple holding both the selected path and the used file type filter), and replace ' with an empty string:

file_path = rfile[0].replace("'", "")
feature_engineer
  • 1,088
  • 8
  • 16