how can I have information about a dir
-
is there a function to know information about a dir like dimension and date of creation?
-
You can use QFileInfo (yes I know it has "file" in name, but it works for directories, too) to get creation date. I have no idea what you mean by "dimension" - directory size? If so, then you need to manually count all the files or use platform-specific APIs to get the size. QFileInfo will only return you the size of directory descriptor.
-
@sierdzio I wrote:
QFileInfo fi(path_definitivo); double dimensione = fi.size(); QString dim_bytes = QString::number(dimensione);
"fi" is a dir, but dimensione is 0, but it'isn't possible because inside dir there is a file that has a size of 1kb
-
QFileInfo works on Dirs too, but not in general.
Returns the file size in bytes. If the file does not exist or cannot be fetched, 0 is returned.
It seems XY.size() does not work on directories
If you need a reliable solution, you have to iterate through all sub-directories and sum all file sizes
-
No OS (well, Linux or Windows at least) offers a "size" attribute on directories which gives the size of all its contents, or for that matter the number of children, whether you use
QFileInfo
or not. It would be too slow/hard to maintain updated. If you want to know either of those you have to walk all the children (recursively if you want to know about sub-content) and count for yourself. -
@vale88 said in how can I have information about a dir:
"fi" is a dir, but dimensione is 0, but it'isn't possible because inside dir there is a file that has a size of 1kb
As I already wrote:
you need to manually count all the files or use platform-specific APIs to get the size. QFileInfo will only return you the size of directory descriptor.