1.文件的读写
2.遍历一个目录下所有文件
#ifndef FILEOPERATE_H
#define FILEOPERATE_H
#include <QWidget>
#include <QDir>
#include <QFileDialog>
#include <QString>
#include <QStringList>
#include <QFileInfoList>
#include <QFileInfo>
#include <QFile>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class FileOperate; }
QT_END_NAMESPACE
class FileOperate : public QWidget
{
Q_OBJECT
public:
FileOperate(QWidget *parent = nullptr);
~FileOperate();
QStringList getfileName(QString path);
QString openFile(QString FileName,QString data);
bool printFiles(QString path);
private:
Ui::FileOperate *ui;
QStringList FileName;
int m_nFilesCount;
int m_nDirCount;
};
#endif // FILEOPERATE_H
#include "fileoperate.h"
#include "ui_fileoperate.h"
#include <QDir>
#include <QDateTime>
#define KEY 0
FileOperate::FileOperate(QWidget *parent)
: QWidget(parent)
, ui(new Ui::FileOperate)
{
ui->setupUi(this);
QStringList list = getfileName("F:/FileSystemWatcherTest");
printFiles("F:/FileSystemWatcherTest");
#if KEY //1表示不注释 0表示注释
QStringListIterator it(list);
while(it.hasNext())
{
qDebug()<<it.next().toLocal8Bit().constData();
}
openFile("F:/FileSystemWatcherTest/1.txt","i am the test contents");