- #include <QtGui>
- int main( int argc, char ** argv )
- {
- QApplication a( argc, argv );
- a.setQuitOnLastWindowClosed(true);
- //get the dir name
- QString dirName;
- if( argc <2 )
- {
- QMessageBox::information(0,"debug","-d dirname");
- exit(0);
- }
- else if( strcmp(argv[1],"-d" )==0 )
- dirName = QString::fromLocal8Bit(argv[2]);
- //get the dir information
- QFileInfoList allfile;
- if( !dirName.isEmpty() )
- {
- QDir dir(dirName);
- if( dir.exists() )
- {
- allfile = dir.entryInfoList();
- }
- }
- //get all the file name in this dir
- int i=0;
- if( allfile.count()<=0 )
- {
- QMessageBox::information(0,"debug","there is no file in the dir");
- exit(0);
- }
- else
- {
- //create the file to store the filename
- QFile songfile(dirName+"/songname.txt");
- bool openflag = false;
- openflag = songfile.open(QIODevice::WriteOnly|QIODevice::Text);
- if( openflag )
- {
- QTextStream out(&songfile);
- for(i=0;i<allfile.count();++i)
- {
- QFileInfo info = allfile.at(i);
- out<<info.fileName()<<endl;
-
- }
- songfile.close();
- }
- else
- {
- QMessageBox::information(0,"debug","open error");
- exit(0);
- }
- }//end allfile.count
-
- exit(0);
- //return a.exec();
-
- }
主要是为了方便别人选歌,一个一个歌名显然不是机器时代的做法。
就想到自己用过的qt呵呵:)
还有很多不完善的地方,比如目录下还有目录,这个就要用到递归,还请大家多多指正。
编译测试环境:xp + dev-cpp + qt441