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?
source
share