Folder Properties

Hi! I already made a function that takes a folder path opens it and read how many files and folders are included in the given path.
But however if i use it on a folder with large amount of files and folders in it for example i used it on c:/Program Files which consists of 126 000 files and
11 000 folders on my PC it takes 75 seconds to give this info on screen.
I'm making console app so i wanted to ask if there is a faster way to get this info like is there a way to use windows folder properties that gives entire info for a selected folder (like size,date modified,content and etc)
cos i really wanna lower the time for getting this info.
Thanks in advance!
P.S. I'm also using boost 1.48.0 library on the academy!
Last edited on
SpecijalkaPP wrote:
I'm making console app so i wanted to ask if there is a faster way to get this info ...


We cannot say if there's a faster way if you don't show your current way. Show how you are doing it now.
Here is the function code using boost lib 1.48.0
Note! it takes around 75 seconds to count 130 000 files and 11 000 folders and i want to make this time to be at least half of the current one!


void CFolder(string pateka)
{
boost::filesystem3::recursive_directory_iterator kraj;
if(boost::filesystem3::is_directory(pateka))
{
int SumFolderi=0;
int SumFiles=0;
for(boost::filesystem3::recursive_directory_iterator pocetok(pateka);pocetok!=kraj;pocetok++)
{
if(boost::filesystem3::is_directory(pocetok->path().string()))
{
SumFolderi++;
}
if(boost::filesystem3::is_regular_file(pocetok->path().string()))
{
SumFiles++;
}
}
cout<<SumFolderi<<" Folders"<<endl;
cout<<SumFiles<<" Files"<<endl;
}
else
{
cout<<"Ne postoi folder so dadenata pateka "<<endl;
cout<<"Vnesete nova pateka "<<endl;
getline(cin,pateka);
CFolder(pateka);
}
}
That looks expensive. Are you supposed to pass a string to is_directory and is_regular_file? Shouldn't you just pass path()? I haven't used boost::filesystem, but it doesn't look right to me.
When libraries fail, resort to the Windows API directly. Use FindFirstFile().
kbw

I don't know what's the price for the boost lib but the academy has it so i don't mind using it :D
it works perfectly fine on boost 1.48.0 using strings
you can use all functions that take path() with an ordinary string which will be something like c:\users\Desktop etc. if the string is folder path the function works properly else gives out info that the path is not from a folder and makes the user to enter new path (string).

webJose

the library doesn't fails it's just too much time to read entire content of a folder
if you do select the folder and go right click ->properties it will use like 20 seconds to count all the files and folder included in that folder and this code takes 75 seconds :D
if i remake the two if() statements with one if(){}else{} it might work faster i will check that now
if you do search for a file using file name and folder where is it it takes same or less time than the windows search function so its damn nice.
PLS explain me how to use FindFirstFile() or even better make the code similar like the one i posted doing the same check count so i can measure the time if it goes faster than mine ty
Last edited on
SpecijalkaPP

i saw your old code and i think it is great, but i don't see why it should work so slow
can u give us the code for the solution you have right now?
i think that i can help ya
This was just a function i started creating so i can use it to compare 2 folders if they are identical or one of the is a copy of the other so i was thinking best way to start is to see if the number of files and folders is equal. But i guess i will have to make a new solution with a different way of thinking 'cos its obvious that this takes too much time so i guess i will have to make new logic solution for it.
I ment to go this way:
step 1 compare the size of the folders.
step 2 compare the No of files and folders in both folders
step 3 if the above 2 steps are true we go read all the content from the both folders taking info for each file like name path in the folder and hash code for all of them and collect them into vector for example or list but not in map cos it will loose the hierarchy cos the recursive_dir_iterator goes step by step from start to bottom and it gives good hierarchy in the folder itself
step 4 compare both containers via hash code if all files are the same they must be copy or copy with changed name.
But since this takes too long i will have to look for another way to do it faster.
P.S. i've changed the if statements with one if statement it goes for 65 seconds to read the total number of files and folder which is a long time to be honest so i'm gonna think for a faster way cos the time for executing is important for this project
Well SpecijalkaPP, i would like to take a little peek at your code to see what haven't you written and what you should write. If you don't want to show your code in public, you can send it to me via private message. I have worked with boost 1.47 filesystem for searching irregular files and i have found some similar problems like yours
I don't mind sending the code it's just it is on a pc that has not and will not have access to the internet so it's not a matter of do i want to or not.
I have a problem that goes something like this:
I need to read all the files from a folder which for a test its going to be like maybe 200 000+ files in a single folder.
The task i need to perform is this:
read all the files from this folder and compare them all to find files that are identical using hash functions that will read the files.
So testing this code above it seems to work well reading 200 000 files cos it worked around 89 seconds to read all the files and get info for them.
The info i took was this: get the file extensions, path(),file_size() and Last_Write_Time() on each file for those 89 seconds which is fast enough.
Next i need to make is another function that will compare all of these files
I tried using this: i compared 2 files at a time checking if they got same file_size and same extensions. If this statement get value true i read them with hash function and i compare both hash codes if they are same the files are identical and i store them .
I'm using list container btw .
But this takes too long over 20 minutes. And i need to find faster solution to check them all.
i would gladly like to help you but i can not do that until i see the code :(
I came up with a solution so this matter is done :D
Thanks for everyone who had time to help!
Topic archived. No new replies allowed.