Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i change a file extension on qt

I have a piece of code to download a file from server. However, due to server constraint, I can not put .exe file at server. So I rename my XXX.exe file to XXX.alt(just a random extension) and put it on server. Now my code can download XXX.alt, but how can I change the file name from XXX.alt back to XXX.exe when in QT environment?

like image 202
Nicholas Yu Avatar asked Nov 28 '22 23:11

Nicholas Yu


2 Answers

Use QFileInfo to get the path without the last extension then append the new extension.

QFileInfo info(fileName);
QString strNewName = info.path() + "/" + info.completeBaseName() + ".exe";
like image 132
drescherjm Avatar answered Dec 20 '22 16:12

drescherjm


Just use rename function from 'stdio.h'.

char oldname[] ="XXX.alt";
char newname[] ="XXX.exe";
result= rename( oldname , newname );
if ( result == 0 )
  puts ( "File successfully renamed" );
else
  perror( "Error renaming file" );
like image 27
Ashot Khachatryan Avatar answered Dec 20 '22 16:12

Ashot Khachatryan