Creating a directory file using QFile

I wonder if it is possible to create a file with its directories in one go. For example, I want to create file scripts /myFile.txt.

I wrote this code:

QFile _file( path );
QDir _dir;

// check if "scripts" folder exists
int _dirExists = _dir.exists( "scripts" );
// if not, create it
if( !_dirExists )
    _dir.mkdir( "scripts" );

// open file in write mode (and text mode) 
int _fileOpened = _file.open( QIODevice::WriteOnly | QIODevice::Text );
if( !_fileOpened ) {
// ...

but I had to use the QDir class and I don't like the way it looks. I cannot understand why QFile does not create the necessary directories, as in most similar infrastructures. Or maybe I missed something?

+5
source share
2 answers

I know his years afterword, but QDir :: mkpath just worked for me.

http://qt-project.org/doc/qt-4.8/qdir.html#mkpath

+8
source

No, I believe that you cannot create a file and contain a directory in one shot.

+4
source

All Articles