Working on a new program to make backups of certain files but it will not open those files. The program starts by reading in a text file with a list of files to backup to the applications directory. The text file loads correctly when the application starts, but when i press on the backup button it gives me an error message: The filename, directory name, or volume label syntax is incorrect.

When I first started creating this app it would only read and copy one out of three files I was using for testing. After changing a few things around to attempt to fix the issue it wont even copy a single file. It is rather confusing on why one instance of QFile works while the other doesn't. I have tried changing the information in the text file from C:/test/filename to C:\test\file C:\\test\\file C://test//file and I get the same error.

Qt Code:
  1. void SunBak::onBackup()
  2. {
  3. while (it != FBak.end())
  4. {
  5. // Grab file
  6. QByteArray data;
  7. QString filename = it->FullPath();
  8. QMessageBox::information(this, tr("Backing up file."),
  9. tr("%1") .arg(filename));
  10. QFile file(filename);
  11. if (!file.open(QIODevice::ReadOnly))
  12. {
  13. QMessageBox::information(this, tr("Unable to open file"), file.errorString());
  14. return;
  15. }
  16. data = file.readAll();
  17. if (data.isEmpty()){ QMessageBox::warning(this, tr("Not reading data!"), tr("What the hell?")); }
  18. file.close();
  19.  
  20. filename = it->getFile();
  21. QMessageBox::information(this, tr("Test:"), tr("%1") .arg(filename));
  22. QFile fileSave(filename);
  23. //file.open(QIODevice::WriteOnly);
  24. if (!fileSave.open(QIODevice::WriteOnly))
  25. {
  26. QMessageBox::information(this, tr("Unable to open file"), fileSave.errorString());
  27. // return;
  28. }
  29. if (fileSave.write(data) == -1)
  30. {
  31. QMessageBox::critical(this, tr("Error!"), tr("File %1 not written!") .arg(filename));
  32. }
  33. it++;
  34. }
  35. }
To copy to clipboard, switch view to plain text mode