PDA

View Full Version : Problem while trying to copy an XML file from one location to another in Linux



payal
11th March 2010, 09:53
Hi all,

I am facing one problem while copying an XML file from one place to another place in my filesystem.I am using following code for copying. Test1 and Test2 are the different folders.

but everytime both the boolean variables are returning false.I dont have any idea.

Could anyone plz help me ?



QString FirstPath = QDir::currentPath()+QDir::separator()+"Test1"+ QDir::separator() +"Test1.xml";
FirstPath = QDir::toNativeSeparators(FirstPath);
qDebug()<<FirstPath;

QString SecondFilePath = QDir::currentPath()+QDir::separator()+"Test1" + QDir::separator()+ "Test2" +QDir::separator()+ "Test2.xml";
SecondFilePath = QDir::toNativeSeparators(SecondFilePath);
qDebug()<<SecondFilePath;
QFile file;

if (!file.exists(FirstPath))
{
QFile file(SecondFilePath);
bool ret1= file.copy(FirstPath);
qDebug()<<ret1;
}
QFile prefFile(FirstPath);

bool ret2= prefFile.setPermissions(QFile::WriteUser);
qDebug()<<ret2;

Trying to access these paths,

Test1->Test2->Test2.xml & Test1->Test1.xml

TMan
11th March 2010, 10:44
Why don't you use: bool QFile::copy ( const QString & fileName, const QString & newName ) [static]

Furthermore, did you check whether the source file exists according to QFile?

high_flyer
11th March 2010, 10:44
Are you trying to overwrite a file?

Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it).

payal
11th March 2010, 12:49
yaa, i tried with bool QFile::copy ( const QString & fileName, const QString & newName ) [static] also...............


but the result is same....its not copied............

Lykurg
11th March 2010, 13:52
Your code is confusing. What are you trying? Copying FirstPath to SecondFilePath or SecondFilePath to FirstPath. If you want "FirstPath to SecondFilePath" then your syntax if wrong.
How does your file system and privileges look like? Post the return of "ls -lAhR" inside your directory: QDir::currentPath()+QDir::separator()+"Test1".

EDIT: forget about the "ls -lAhR" since you are working on windows. Then you must write it by hand...