How to print only the file name of a path
Hi to all,
with a QFileDialog I choose a file in my hard disk to process it.
I would to print (with a cout) only the filename instead of the whole path.
Here the code
Code:
void CoinWidget::openAudioTrack()
{
tr("Audio (*.wav *.mp3);;All Files(*)"),
this,
"open file dialog",
"Choose an audio track");
if(!audioFileName.isEmpty())
{
cout << audioFileName.latin1() << endl; //<-----this print the whole path
// retrieve the root separator
SoSeparator *lroot = model->getRoot();//about coin3d
m_sound->setAudioTrack(audioFileName.latin1());
m_sound->enableContinuousPlay(true);
m_sound->setVolume(0.5f);
m_sound->playTrack();
}
else
{
cout << "No file selected" << endl;
return;
}
}
Where I wrote "this print the whole path" I also would print the filename istead.
Any idea?
Regards
Re: How to print only the file name of a path
try this
Code:
...
cout << audioFileName.section('/', -1).latin1() << endl;
...
Re: How to print only the file name of a path
This solution is more elegant:
Code:
cout << fi.fileName().latin1() << endl;
Re: How to print only the file name of a path
Thank you very much.
It works in both cases.
Regards,
Franco