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?
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";
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" );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With