自动生成测试用文件

项目需要大量测试用文件,下面代码用Qt 编程自动生成50000个测试用txt文件。

没什么技术难度,仅作备份。

    static long i = 0;
    for( ; i<= 50000; i++)
    {
        QString fName = QString("File-%1.txt").arg(i,10,10,QLatin1Char('0'));
        QFile fileOut( fName );

        if (!fileOut.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text))
        {
            return false;
        }
        QTextStream streamFileOut(&fileOut);
        streamFileOut.setCodec("UTF-8");

        streamFileOut << QString( "    File Name : %1\r\n" ).arg(fName);
        streamFileOut << QString( "  Create Time : %1\r\n" ).arg(QDateTime::currentMSecsSinceEpoch());
        streamFileOut << QString( " ## This file is generated by NVR App automatically \n" );
        streamFileOut << QString( " ## Please don't modify manually \n" );

        for( int j=1;  j < 100 ; j++ )
        {
            streamFileOut <<  "\nUsage: unison [options]                                                           "
                              "\n            or unison root1 root2 [options]                                                   "
                              "\n            or unison profilename [options]                                                   "
                              "\n                                                                                              "
                              "\n        Basic options:                                                                        "
                              "\n         -auto              automatically accept default (nonconflicting) actions             "
                              "\n         -batch             batch mode: ask no questions at all                               "
                              "\n         -doc xxx           show documentation ('-doc topics' lists topics)                   "
                              "\n         -fat               use appropriate options for FAT filesystems                       "
                              "\n         -group             synchronize group attributes                                      "
                              "\n         -ignore xxx        add a pattern to the ignore list                                  "
                              "\n         -ignorenot xxx     add a pattern to the ignorenot list                               "
                              "\n         -nocreation xxx    prevent file creations on one replica                             "
                              "\n         -nodeletion xxx    prevent file deletions on one replica                             "
                              "\n         -noupdate xxx      prevent file updates and deletions on one replica                 "
                              "\n         -owner             synchronize owner                                                 "
                              "\n         -path xxx          path to synchronize                                               "
                              "\n         -perms n           part of the permissions which is synchronized                     "
                              "\n         -root xxx          root of a replica (should be used exactly twice)                  "
                              "\n         -silent            print nothing except error messages                               "
                              "\n         -terse             suppress status messages                                          "
                              "\n         -testserver        exit immediately after the connection to the server               "
                              "\n         -times             synchronize modification times                                    "
                              "\n         -version           print version and exit                                            "
                              "\n                                                                                              "
                              "\n        Advanced options:                                                                     "
                              "\n         -addprefsto xxx    file to add new prefs to                                          "
                              "\n         -addversionno      add version number to name of unison on server                    "
                              "\n         -backup xxx        add a pattern to the backup list                                  "
                              "\n         -backupcurr xxx    add a pattern to the backupcurr list                              "
                              "\n         -backupcurrnot xxx add a pattern to the backupcurrnot list                           "
                              "\n         -backupdir xxx     directory for storing centralized backups                         "
                              "\n         -backuploc xxx     where backups are stored ('local' or 'central')                   "
                              "\n         -backupnot xxx     add a pattern to the backupnot list                               "
                              "\n         -backupprefix xxx  prefix for the names of backup files                              "
                              "\n         -backups           keep backup copies of all files (see also 'backup')               "
                              "\n         -backupsuffix xxx  a suffix to be added to names of backup files                     "
                              "\n         -clientHostName xxx set host name of client                                          "
                              "\n         -confirmbigdel     ask about whole-replica (or path) deletes (default true)          "
                              "\n         -confirmmerge      ask for confirmation before committing results of a merge         "
                              "\n         -contactquietly    suppress the 'contacting server' message during startup           "
                              "\n         -copymax n         maximum number of simultaneous copyprog transfers                 "
                              "\n         -copyonconflict    keep copies of conflicting files                                  "
                              "\n         -copyprog xxx      external program for copying large files                          "
                              "\n         -copyprogrest xxx  variant of copyprog for resuming partial transfers                "
            streamFileOut << QString( "\r\nNumber   : %1, %2, %3, %4 \r\n" ).arg( j ).arg(j*j).arg(j*j*j).arg(j*j*j*j);
        }
        streamFileOut.flush();
        fileOut.close();
    }

你可能感兴趣的:(Qt5,c++,qt)