Why the size of the directory is more then 79mb but in fact its about 19mb?
s = Environment.GetEnvironmentVariable("UserProfile") + "\\Pictures";
string[] extensions = { "*.bmp", "*.jpg", "*.png", "*.gif"
};//add extensions you want to filter first
var photosfiles = extensions.SelectMany(x =>
Directory.GetFiles(s, x));
//string[] photosfiles = Directory.GetFiles(s, "*.*",
SearchOption.AllDirectories);
for (int i = 0; i < photosfiles.ToArray().Length; i++)
{
FileInfo fi = new FileInfo((photosfiles.ToArray()[i]));
DirectoryInfo d = new DirectoryInfo(tempphotos);
long dirSize = DirSize(d);
//if copying the file would take the directory over 50MB
then don't do it
if ((dirSize + fi.Length) <= 24117248)
fi.CopyTo(tempphotos + "\\" + fi.Name,true);
else
break;
}
What i changed is this :
string[] extensions = { "*.bmp", "*.jpg", "*.png", "*.gif" };//add
extensions you want to filter first
var photosfiles = extensions.SelectMany(x => Directory.GetFiles(s, x));
Before this two lines i had one line only:
string[] photosfiles = Directory.GetFiles(s, "*.*",
SearchOption.AllDirectories);
With this line it was working but after changed to the two lines above its
not working.
I had to change this lines and add now .ToArray()
for (int i = 0; i < photosfiles.ToArray().Length; i++)
{
FileInfo fi = new FileInfo((photosfiles.ToArray()[i]));
And then the result in the end is that
dirSize + fi.Length = 19526637 And fi.Length = 7916391
So its jumping right to the break.
When i used the first time only one line string[] photosfiles =
Directory.GetFiles(s, ".", SearchOption.AllDirectories);
And then without the .ToArray()
It was working good it was copying the files and then do the break;
Why now its not working after changed to this two lines and added the
.ToArray() ?
No comments:
Post a Comment