Posted By

shadevampire on 06/02/11


Tagged

file folder filter files directory rename Qt


Versions (?)

Rename filtered files in directory with Qt


 / Published in: C++
 

URL: http://www.wikihow.com/Rename-Files-in-QT

for more info see the link

  1. /**
  2.  * Prakash Manandhar, http://p-manandhar.info
  3.  * Rename all *4.a files in a directory to add a d before the 4.
  4.  */
  5. #include <QtCore>
  6. #include <QtGui>
  7.  
  8. int main (int argc, char ** argv)
  9. {
  10. char * path;
  11. if (argc == 1) path = ".";
  12. else path = argv[1];
  13. QDir dir (path);
  14. QStringList filters ("*4.a");
  15. QFileInfoList list = dir.entryInfoList (filters);
  16. for (int i = 0; i < list.size(); ++i) {
  17. QFileInfo fInfo = list.at(i);
  18. QString fPath = fInfo.absoluteFilePath();
  19. qDebug() << fPath;
  20. QFile file (fPath);
  21. QString fPath_ren = fPath;
  22. fPath_ren.chop(3);
  23. fPath_ren += "d4.a";
  24. dir.rename(fPath, fPath_ren);
  25. }
  26. return 0;
  27. }

Report this snippet  

You need to login to post a comment.