473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Scanning hard drive

Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey
Oct 21 '07 #1
23 3708
It depends entirely on how you are doing the writing code! 13 or 4
mins sounds big - how much data?

Oct 21 '07 #2
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.
How much, what are your expectations? The running time will depend on the
number of folders and files and the amount of info you are storing in the
list.
So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.
This is normal, the "fileinfo" was cached in the filesystem cache with the
last run, this highly reduces the Filesystem IO rate to get at the file
information.
I am wondering if I can improve on this even more??
My guess is that your system starts paging because you are exhausting the
Free RAM space with the data in your list. So, you need to start looking at
your memory consumption, and change your design, for instance by serializing
the List as a File on disk per directory you have scanned.
Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?
No, this has nothing to do with the language, really.
Willy.

Oct 21 '07 #3
It depends entirely on how you are doing the writing code! 13 or 4
mins sounds big - how much data?
Ignore; I misread the question

Oct 21 '07 #4
Interesting, I rebooted and ran it.

This time approx 10 mins to scan 56GB.

It seems you are write that the fileinfo was being cached.

I checked mem usage in task manager and it say 110MB
for the app after it ran.

Which is not a problem if you 2GB like me or even 1GB really.

So I don't see why it would have paging issues, do you think??

So you don't think I can improve on this??????

Malcolm

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:OH**************@TK2MSFTNGP03.phx.gbl...
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
>Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

How much, what are your expectations? The running time will depend on the
number of folders and files and the amount of info you are storing in the
list.
>So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

This is normal, the "fileinfo" was cached in the filesystem cache with the
last run, this highly reduces the Filesystem IO rate to get at the file
information.
>I am wondering if I can improve on this even more??
My guess is that your system starts paging because you are exhausting the
Free RAM space with the data in your list. So, you need to start looking
at your memory consumption, and change your design, for instance by
serializing the List as a File on disk per directory you have scanned.
>Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

No, this has nothing to do with the language, really.
Willy.

Oct 21 '07 #5
Rotsey wrote:
Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.
That's not because you've used a struct. It's because the data is cached
by the operating system. Restart your computer and try it again.

The problem is the speed that you can get the data from the disk. There
isn't a lot you can do about that (except buy a faster hard disk, or
delete data, or make sure your OS is caching the stuff)

Alun Harford
Oct 21 '07 #6
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ua*************@TK2MSFTNGP06.phx.gbl...
Interesting, I rebooted and ran it.

This time approx 10 mins to scan 56GB.

It seems you are write that the fileinfo was being cached.

I checked mem usage in task manager and it say 110MB
for the app after it ran.
You need to look while it runs, not after it ran, and you need to use
perfmon to watch the working set size and the private bytes.
Which is not a problem if you 2GB like me or even 1GB really.

So I don't see why it would have paging issues, do you think??
This shouldn't be an issue, unless you have a very large number of files
stored on disk and you are storing a lot of file properties in the list.
Most likely is that you are running this on a slow disk and/or system. Most
info must be retrieved from disk, this involves Disk IO , but 10 minutes
to get at this info is really slow, even 4 minutes for a second run is quite
slow.

That said, you need to tell us how many files you have on disk, what data
you are storing in the list, what OS and system HW you are running this on,
and (preferably) post a complete sample that illustrates the issue.

Willy.

Oct 21 '07 #7
What do you scan? I do a directory and File scan in my 100GB (64GB of data)
hard drive and took 24 seconds. (Scanned every directory and every file in
the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey

Oct 21 '07 #8
OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1, ref
double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@microsof t.com...
What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and every
file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
>Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey


Oct 22 '07 #9
Approx. 13 seconds on a 250GB disk with 30,000+ directories and 1,000,000+
files.

What is DriveData? (You omitted to post it).

What do you do with the content of DriveData when the call to
ScanFolder(...) returns?

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1, ref
double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@microsof t.com...
>What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and every
file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
>>Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey


Oct 22 '07 #10
Sorry about that , but it just a class with the generic list and a string
drive property

All I am doing is displaying some of the info when ScanFolder returns
But that is after the scan completes of course which is not the problem.

Any chance of seeing your code???

public class DriveData

{

private List<PieFileInfomList = new List<PieFileInfo>();

public List<PieFileInfoDataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

public string Drive

{

get { return mDrive; }

set { mDrive = value; }

}

}

"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Approx. 13 seconds on a 250GB disk with 30,000+ directories and 1,000,000+
files.

What is DriveData? (You omitted to post it).

What do you do with the content of DriveData when the call to
ScanFolder(...) returns?

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
>OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@microso ft.com...
>>What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and every
file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey


Oct 22 '07 #11
It was YOUR code!
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Sorry about that , but it just a class with the generic list and a string
drive property

All I am doing is displaying some of the info when ScanFolder returns
But that is after the scan completes of course which is not the problem.

Any chance of seeing your code???

public class DriveData

{

private List<PieFileInfomList = new List<PieFileInfo>();

public List<PieFileInfoDataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

public string Drive

{

get { return mDrive; }

set { mDrive = value; }

}

}

"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Approx. 13 seconds on a 250GB disk with 30,000+ directories and
1,000,000+ files.

What is DriveData? (You omitted to post it).

What do you do with the content of DriveData when the call to
ScanFolder(...) returns?

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
>>OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setting sData.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setting sData.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Setting sData.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Setting sData.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@micros oft.com...
What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and
every file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
Hi,
>
I am writing an app that scans hard drives and logs info
about every fine on the drive.
>
The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.
>
I wanted it to be quicker.
>
So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.
>
I am wondering if I can improve on this even more??
>
Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?
>
rotsey
>
>

Oct 22 '07 #12
Sorry Stephen what do you mean?

"Stephany Young" <noone@localhostwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
It was YOUR code!
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>Sorry about that , but it just a class with the generic list and a string
drive property

All I am doing is displaying some of the info when ScanFolder returns
But that is after the scan completes of course which is not the problem.

Any chance of seeing your code???

public class DriveData

{

private List<PieFileInfomList = new List<PieFileInfo>();

public List<PieFileInfoDataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

public string Drive

{

get { return mDrive; }

set { mDrive = value; }

}

}

"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>Approx. 13 seconds on a 250GB disk with 30,000+ directories and
1,000,000+ files.

What is DriveData? (You omitted to post it).

What do you do with the content of DriveData when the call to
ScanFolder(...) returns?

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settin gsData.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settin gsData.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Settin gsData.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Settin gsData.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@micro soft.com...
What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and
every file in the drive for info).
>
PD: for reference 170,187 files and 21,899 folders.
>
>
Regards,
>
Bela Istok
>
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl.. .
>Hi,
>>
>I am writing an app that scans hard drives and logs info
>about every fine on the drive.
>>
>The first iteration of my code used a class and a generic list
>to store the data and rhis took 13min on my 60 GB drive.
>>
>I wanted it to be quicker.
>>
>So the second time I changed the class to a struct and still
>with the generic list got the time down to 4 min.
>>
>I am wondering if I can improve on this even more??
>>
>Anyone know if it would be possible to improve this
>using C# or would it need to be wrritten in assembler or the like?
>>
>rotsey
>>
>>
>


Oct 22 '07 #13
It's Stephany!

You asked 'Any chance of seeing your code???'

I replied 'It was your code (that I ran)'.

The DriveData class did not add any significant overhead.

I used 10 for Age1Days and 20 for Age2Days.

Here are my results for my main dev machine (Vista).

Drive size1 size2 size3 objects elapsed time
objects per second
-----------------------------------------------------------------------------------------------
C:\ 7,406,454,214 1,166,404,747 45,787,333,348 167,342 1:57.0308662
1429.8962780812093
D:\ 395,375,683 582,398,194 31,460,898,868 59,563 0:11.8571418
5023.3859900368232
E:\ 168 0 87,079,722,334 36,356 0:04.6710676
7783.2313966083470
-----------------------------------------------------------------------------------------------
7,801,830,065 1,748,802,941 164,328,154,550 263,461 2:13.5590756
1972.6177260244529

Grand Total: 173,878,787,556 (161.937240 GB)

C:\ drive is the system drive and has the paging file so those 2 aspects go
someway to explaining the slower rate.

Quite acceptable!
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:e6**************@TK2MSFTNGP04.phx.gbl...
Sorry Stephen what do you mean?

"Stephany Young" <noone@localhostwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
>It was YOUR code!
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>Sorry about that , but it just a class with the generic list and a
string drive property

All I am doing is displaying some of the info when ScanFolder returns
But that is after the scan completes of course which is not the problem.

Any chance of seeing your code???

public class DriveData

{

private List<PieFileInfomList = new List<PieFileInfo>();

public List<PieFileInfoDataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

public string Drive

{

get { return mDrive; }

set { mDrive = value; }

}

}

"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl.. .
Approx. 13 seconds on a 250GB disk with 30,000+ directories and
1,000,000+ files.

What is DriveData? (You omitted to post it).

What do you do with the content of DriveData when the call to
ScanFolder(...) returns?

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
OK. Here is the class the scans the drive.
>
Can you see any issues here?
>
Bela, would you be able to post your code that scans the drive.
>
I am scanning 56GB in about 10 minutes.
public struct PieFileInfo
>
{
>
public int RowID;
>
public PieInfoType Type;
>
public string Name;
>
public string FullName;
>
public double Filesize;
>
public DateTime LastAccess;
>
public DateTime Created;
>
public string Extension;
>
public DateTime LastWrite;
>
public int ParentFolderRowID;
>
public string Drive;
>
public double FileAge1;
>
public double FileAge2;
>
public double FileAge3;
>
public bool IsRoot;
>
}
>
public class ScanDrive
>
{
>
private DriveData mList = new DriveData();
>
public DriveData DataList
>
{
>
get { return mList; }
>
set { mList = value; }
>
}
>
private string mDrive;
>
private int mNewFolderID = 0;
>
public ScanDrive(string drivefolder)
>
{
>
mDrive = drivefolder;
>
mList.Drive = drivefolder;
>
}
>
public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)
>
{
>
DirectoryInfo objDir = new DirectoryInfo(folder);
>
int newFolderID;
>
double size1 = 0;
>
double size2 = 0;
>
double size3 = 0;
>
System.DateTime fileDate;
>
try
>
{
>
newFolderID = WriteRow(objDir, folderID);
>
if (newFolderID == 0)
>
{
>
return false;
>
}
>
foreach (DirectoryInfo dir in objDir.GetDirectories())
>
{
>
if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))
>
{
>
return true;
>
}
>
size1 += psize1;
>
size2 += psize2;
>
size3 += psize3;
>
}
>
foreach (FileInfo fle in objDir.GetFiles())
>
{
>
WriteRow(fle, newFolderID);
>
fileDate = GetAgeDate(fle);
>
if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age1Days * -1))
>
size1 += fle.Length;
>
else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age2Days * -1))
>
size2 += fle.Length;
>
else
>
size3 += fle.Length;
>
}
>
UpdateFolderRow(newFolderID, size1, size2, size3);
>
psize1 = size1;
>
psize2 = size2;
>
psize3 = size3;
>
return true;
>
}
>
catch (Exception)
>
{
>
return true;
>
}
>
>
>
}
>
private DateTime GetAgeDate(FileInfo f)
>
{
>
if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age1Days * -1))
>
return f.CreationTime;
>
else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age2Days * -1))
>
return f.LastWriteTime;
>
else
>
return f.LastAccessTime;
>
}
>
private int WriteRow(DirectoryInfo dir, int folderID)
>
{
>
PieFileInfo info = new PieFileInfo();
>
if (mNewFolderID == 0)
>
info.IsRoot = true;
>
mNewFolderID++;
>
info.RowID = mNewFolderID;
>
info.Type = PieInfoType.Folder;
>
info.FullName = dir.FullName;
>
info.Name = dir.Name;
>
info.LastAccess = dir.LastAccessTime;
>
info.LastWrite = dir.LastWriteTime;
>
info.Created = dir.CreationTime;
>
info.ParentFolderRowID = folderID;
>
info.Drive = mDrive;
>
mList.DataList.Add(info);
>
return mNewFolderID;
>
}
>
private int WriteRow(FileInfo file, int folderID)
>
{
>
PieFileInfo info = new PieFileInfo();
>
info.Type = PieInfoType.File;
>
info.Name = file.Name;
>
info.FullName = file.FullName;
>
info.Filesize = file.Length;
>
info.Extension = file.Extension;
>
info.LastAccess = file.LastAccessTime;
>
info.LastWrite = file.LastWriteTime;
>
info.Created = file.CreationTime;
>
info.ParentFolderRowID = folderID;
>
info.Drive = mDrive;
>
if (file.LastAccessTime >= DateTime.Today.AddDays(-30))
>
info.FileAge1 = file.Length;
>
else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))
>
info.FileAge2 = file.Length;
>
else
>
info.FileAge3 = file.Length;
>
mList.DataList.Add(info);
>
return folderID;
>
}
>
private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)
>
{
>
int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)
>
{
>
if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)
>
return true;
>
else
>
return false;
>
});
>
PieFileInfo info = mList.DataList[index];
>
info.FileAge1 += size1;
>
info.FileAge2 += size2;
>
info.FileAge3 += size3;
>
info.Filesize += size1 + size2 + size3;
>
mList.DataList[index] = info;
>
}
>
}
>
>
>
"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@micr osoft.com...
>What do you scan? I do a directory and File scan in my 100GB (64GB of
>data) hard drive and took 24 seconds. (Scanned every directory and
>every file in the drive for info).
>>
>PD: for reference 170,187 files and 21,899 folders.
>>
>>
>Regards,
>>
>Bela Istok
>>
>"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
>news:er**************@TK2MSFTNGP05.phx.gbl. ..
>>Hi,
>>>
>>I am writing an app that scans hard drives and logs info
>>about every fine on the drive.
>>>
>>The first iteration of my code used a class and a generic list
>>to store the data and rhis took 13min on my 60 GB drive.
>>>
>>I wanted it to be quicker.
>>>
>>So the second time I changed the class to a struct and still
>>with the generic list got the time down to 4 min.
>>>
>>I am wondering if I can improve on this even more??
>>>
>>Anyone know if it would be possible to improve this
>>using C# or would it need to be wrritten in assembler or the like?
>>>
>>rotsey
>>>
>>>
>>
>
>

Oct 22 '07 #14
Oh i see you mean you ran my code on your machine.

surely it can't be that fast

I have a 7200RPM 60GB drive in 1.86GHz Pentium M Laptop

What is your specs?
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:e6**************@TK2MSFTNGP04.phx.gbl...
Sorry Stephen what do you mean?

"Stephany Young" <noone@localhostwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
>It was YOUR code!
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>Sorry about that , but it just a class with the generic list and a
string drive property

All I am doing is displaying some of the info when ScanFolder returns
But that is after the scan completes of course which is not the problem.

Any chance of seeing your code???

public class DriveData

{

private List<PieFileInfomList = new List<PieFileInfo>();

public List<PieFileInfoDataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

public string Drive

{

get { return mDrive; }

set { mDrive = value; }

}

}

"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl.. .
Approx. 13 seconds on a 250GB disk with 30,000+ directories and
1,000,000+ files.

What is DriveData? (You omitted to post it).

What do you do with the content of DriveData when the call to
ScanFolder(...) returns?

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
OK. Here is the class the scans the drive.
>
Can you see any issues here?
>
Bela, would you be able to post your code that scans the drive.
>
I am scanning 56GB in about 10 minutes.
public struct PieFileInfo
>
{
>
public int RowID;
>
public PieInfoType Type;
>
public string Name;
>
public string FullName;
>
public double Filesize;
>
public DateTime LastAccess;
>
public DateTime Created;
>
public string Extension;
>
public DateTime LastWrite;
>
public int ParentFolderRowID;
>
public string Drive;
>
public double FileAge1;
>
public double FileAge2;
>
public double FileAge3;
>
public bool IsRoot;
>
}
>
public class ScanDrive
>
{
>
private DriveData mList = new DriveData();
>
public DriveData DataList
>
{
>
get { return mList; }
>
set { mList = value; }
>
}
>
private string mDrive;
>
private int mNewFolderID = 0;
>
public ScanDrive(string drivefolder)
>
{
>
mDrive = drivefolder;
>
mList.Drive = drivefolder;
>
}
>
public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)
>
{
>
DirectoryInfo objDir = new DirectoryInfo(folder);
>
int newFolderID;
>
double size1 = 0;
>
double size2 = 0;
>
double size3 = 0;
>
System.DateTime fileDate;
>
try
>
{
>
newFolderID = WriteRow(objDir, folderID);
>
if (newFolderID == 0)
>
{
>
return false;
>
}
>
foreach (DirectoryInfo dir in objDir.GetDirectories())
>
{
>
if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))
>
{
>
return true;
>
}
>
size1 += psize1;
>
size2 += psize2;
>
size3 += psize3;
>
}
>
foreach (FileInfo fle in objDir.GetFiles())
>
{
>
WriteRow(fle, newFolderID);
>
fileDate = GetAgeDate(fle);
>
if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age1Days * -1))
>
size1 += fle.Length;
>
else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age2Days * -1))
>
size2 += fle.Length;
>
else
>
size3 += fle.Length;
>
}
>
UpdateFolderRow(newFolderID, size1, size2, size3);
>
psize1 = size1;
>
psize2 = size2;
>
psize3 = size3;
>
return true;
>
}
>
catch (Exception)
>
{
>
return true;
>
}
>
>
>
}
>
private DateTime GetAgeDate(FileInfo f)
>
{
>
if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age1Days * -1))
>
return f.CreationTime;
>
else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age2Days * -1))
>
return f.LastWriteTime;
>
else
>
return f.LastAccessTime;
>
}
>
private int WriteRow(DirectoryInfo dir, int folderID)
>
{
>
PieFileInfo info = new PieFileInfo();
>
if (mNewFolderID == 0)
>
info.IsRoot = true;
>
mNewFolderID++;
>
info.RowID = mNewFolderID;
>
info.Type = PieInfoType.Folder;
>
info.FullName = dir.FullName;
>
info.Name = dir.Name;
>
info.LastAccess = dir.LastAccessTime;
>
info.LastWrite = dir.LastWriteTime;
>
info.Created = dir.CreationTime;
>
info.ParentFolderRowID = folderID;
>
info.Drive = mDrive;
>
mList.DataList.Add(info);
>
return mNewFolderID;
>
}
>
private int WriteRow(FileInfo file, int folderID)
>
{
>
PieFileInfo info = new PieFileInfo();
>
info.Type = PieInfoType.File;
>
info.Name = file.Name;
>
info.FullName = file.FullName;
>
info.Filesize = file.Length;
>
info.Extension = file.Extension;
>
info.LastAccess = file.LastAccessTime;
>
info.LastWrite = file.LastWriteTime;
>
info.Created = file.CreationTime;
>
info.ParentFolderRowID = folderID;
>
info.Drive = mDrive;
>
if (file.LastAccessTime >= DateTime.Today.AddDays(-30))
>
info.FileAge1 = file.Length;
>
else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))
>
info.FileAge2 = file.Length;
>
else
>
info.FileAge3 = file.Length;
>
mList.DataList.Add(info);
>
return folderID;
>
}
>
private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)
>
{
>
int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)
>
{
>
if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)
>
return true;
>
else
>
return false;
>
});
>
PieFileInfo info = mList.DataList[index];
>
info.FileAge1 += size1;
>
info.FileAge2 += size2;
>
info.FileAge3 += size3;
>
info.Filesize += size1 + size2 + size3;
>
mList.DataList[index] = info;
>
}
>
}
>
>
>
"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@micr osoft.com...
>What do you scan? I do a directory and File scan in my 100GB (64GB of
>data) hard drive and took 24 seconds. (Scanned every directory and
>every file in the drive for info).
>>
>PD: for reference 170,187 files and 21,899 folders.
>>
>>
>Regards,
>>
>Bela Istok
>>
>"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
>news:er**************@TK2MSFTNGP05.phx.gbl. ..
>>Hi,
>>>
>>I am writing an app that scans hard drives and logs info
>>about every fine on the drive.
>>>
>>The first iteration of my code used a class and a generic list
>>to store the data and rhis took 13min on my 60 GB drive.
>>>
>>I wanted it to be quicker.
>>>
>>So the second time I changed the class to a struct and still
>>with the generic list got the time down to 4 min.
>>>
>>I am wondering if I can improve on this even more??
>>>
>>Anyone know if it would be possible to improve this
>>using C# or would it need to be wrritten in assembler or the like?
>>>
>>rotsey
>>>
>>>
>>
>
>


Oct 22 '07 #15
The earlier run was on a super grunty server with really fast scsi drives,
truckloads of ram and multiple dual-core perocessors.
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:OS**************@TK2MSFTNGP04.phx.gbl...
Oh i see you mean you ran my code on your machine.

surely it can't be that fast

I have a 7200RPM 60GB drive in 1.86GHz Pentium M Laptop

What is your specs?
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:e6**************@TK2MSFTNGP04.phx.gbl...
>Sorry Stephen what do you mean?

"Stephany Young" <noone@localhostwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
>>It was YOUR code!
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl.. .
Sorry about that , but it just a class with the generic list and a
string drive property

All I am doing is displaying some of the info when ScanFolder returns
But that is after the scan completes of course which is not the
problem.

Any chance of seeing your code???

public class DriveData

{

private List<PieFileInfomList = new List<PieFileInfo>();

public List<PieFileInfoDataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

public string Drive

{

get { return mDrive; }

set { mDrive = value; }

}

}

"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl. ..
Approx. 13 seconds on a 250GB disk with 30,000+ directories and
1,000,000+ files.
>
What is DriveData? (You omitted to post it).
>
What do you do with the content of DriveData when the call to
ScanFolder(...) returns?
>
>
>
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl.. .
>OK. Here is the class the scans the drive.
>>
>Can you see any issues here?
>>
>Bela, would you be able to post your code that scans the drive.
>>
>I am scanning 56GB in about 10 minutes.
>public struct PieFileInfo
>>
>{
>>
>public int RowID;
>>
>public PieInfoType Type;
>>
>public string Name;
>>
>public string FullName;
>>
>public double Filesize;
>>
>public DateTime LastAccess;
>>
>public DateTime Created;
>>
>public string Extension;
>>
>public DateTime LastWrite;
>>
>public int ParentFolderRowID;
>>
>public string Drive;
>>
>public double FileAge1;
>>
>public double FileAge2;
>>
>public double FileAge3;
>>
>public bool IsRoot;
>>
>}
>>
>public class ScanDrive
>>
>{
>>
>private DriveData mList = new DriveData();
>>
>public DriveData DataList
>>
>{
>>
>get { return mList; }
>>
>set { mList = value; }
>>
>}
>>
>private string mDrive;
>>
>private int mNewFolderID = 0;
>>
>public ScanDrive(string drivefolder)
>>
>{
>>
>mDrive = drivefolder;
>>
>mList.Drive = drivefolder;
>>
>}
>>
>public bool ScanFolder(string folder, int folderID, ref double
>psize1, ref double psize2, ref double psize3)
>>
>{
>>
>DirectoryInfo objDir = new DirectoryInfo(folder);
>>
>int newFolderID;
>>
>double size1 = 0;
>>
>double size2 = 0;
>>
>double size3 = 0;
>>
>System.DateTime fileDate;
>>
>try
>>
>{
>>
>newFolderID = WriteRow(objDir, folderID);
>>
>if (newFolderID == 0)
>>
>{
>>
>return false;
>>
>}
>>
>foreach (DirectoryInfo dir in objDir.GetDirectories())
>>
>{
>>
>if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
>psize3))
>>
>{
>>
>return true;
>>
>}
>>
>size1 += psize1;
>>
>size2 += psize2;
>>
>size3 += psize3;
>>
>}
>>
>foreach (FileInfo fle in objDir.GetFiles())
>>
>{
>>
>WriteRow(fle, newFolderID);
>>
>fileDate = GetAgeDate(fle);
>>
>if (fileDate >=
>DateTime.Today.AddDays(Settings.Instance.Sett ingsData.Age1Days * -1))
>>
>size1 += fle.Length;
>>
>else if (fileDate >=
>DateTime.Today.AddDays(Settings.Instance.Sett ingsData.Age2Days * -1))
>>
>size2 += fle.Length;
>>
>else
>>
>size3 += fle.Length;
>>
>}
>>
>UpdateFolderRow(newFolderID, size1, size2, size3);
>>
>psize1 = size1;
>>
>psize2 = size2;
>>
>psize3 = size3;
>>
>return true;
>>
>}
>>
>catch (Exception)
>>
>{
>>
>return true;
>>
>}
>>
>>
>>
>}
>>
>private DateTime GetAgeDate(FileInfo f)
>>
>{
>>
>if (f.CreationTime >=
>DateTime.Today.AddDays(Settings.Instance.Sett ingsData.Age1Days * -1))
>>
>return f.CreationTime;
>>
>else if (f.LastWriteTime >=
>DateTime.Today.AddDays(Settings.Instance.Sett ingsData.Age2Days * -1))
>>
>return f.LastWriteTime;
>>
>else
>>
>return f.LastAccessTime;
>>
>}
>>
>private int WriteRow(DirectoryInfo dir, int folderID)
>>
>{
>>
>PieFileInfo info = new PieFileInfo();
>>
>if (mNewFolderID == 0)
>>
>info.IsRoot = true;
>>
>mNewFolderID++;
>>
>info.RowID = mNewFolderID;
>>
>info.Type = PieInfoType.Folder;
>>
>info.FullName = dir.FullName;
>>
>info.Name = dir.Name;
>>
>info.LastAccess = dir.LastAccessTime;
>>
>info.LastWrite = dir.LastWriteTime;
>>
>info.Created = dir.CreationTime;
>>
>info.ParentFolderRowID = folderID;
>>
>info.Drive = mDrive;
>>
>mList.DataList.Add(info);
>>
>return mNewFolderID;
>>
>}
>>
>private int WriteRow(FileInfo file, int folderID)
>>
>{
>>
>PieFileInfo info = new PieFileInfo();
>>
>info.Type = PieInfoType.File;
>>
>info.Name = file.Name;
>>
>info.FullName = file.FullName;
>>
>info.Filesize = file.Length;
>>
>info.Extension = file.Extension;
>>
>info.LastAccess = file.LastAccessTime;
>>
>info.LastWrite = file.LastWriteTime;
>>
>info.Created = file.CreationTime;
>>
>info.ParentFolderRowID = folderID;
>>
>info.Drive = mDrive;
>>
>if (file.LastAccessTime >= DateTime.Today.AddDays(-30))
>>
>info.FileAge1 = file.Length;
>>
>else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))
>>
>info.FileAge2 = file.Length;
>>
>else
>>
>info.FileAge3 = file.Length;
>>
>mList.DataList.Add(info);
>>
>return folderID;
>>
>}
>>
>private void UpdateFolderRow(int folderID, double size1, double
>size2, double size3)
>>
>{
>>
>int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)
>>
>{
>>
>if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)
>>
>return true;
>>
>else
>>
>return false;
>>
>});
>>
>PieFileInfo info = mList.DataList[index];
>>
>info.FileAge1 += size1;
>>
>info.FileAge2 += size2;
>>
>info.FileAge3 += size3;
>>
>info.Filesize += size1 + size2 + size3;
>>
>mList.DataList[index] = info;
>>
>}
>>
>}
>>
>>
>>
>"Bela Istok" <be****@hotmail.comwrote in message
>news:ED**********************************@mic rosoft.com...
>>What do you scan? I do a directory and File scan in my 100GB (64GB
>>of data) hard drive and took 24 seconds. (Scanned every directory
>>and every file in the drive for info).
>>>
>>PD: for reference 170,187 files and 21,899 folders.
>>>
>>>
>>Regards,
>>>
>>Bela Istok
>>>
>>"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
>>news:er**************@TK2MSFTNGP05.phx.gbl.. .
>>>Hi,
>>>>
>>>I am writing an app that scans hard drives and logs info
>>>about every fine on the drive.
>>>>
>>>The first iteration of my code used a class and a generic list
>>>to store the data and rhis took 13min on my 60 GB drive.
>>>>
>>>I wanted it to be quicker.
>>>>
>>>So the second time I changed the class to a struct and still
>>>with the generic list got the time down to 4 min.
>>>>
>>>I am wondering if I can improve on this even more??
>>>>
>>>Anyone know if it would be possible to improve this
>>>using C# or would it need to be wrritten in assembler or the like?
>>>>
>>>rotsey
>>>>
>>>>
>>>
>>
>>
>


Oct 22 '07 #16
Sorry Stephany!!!

I see well that explains 2 min approx for C Drive.

I am trying to gauge what would be the case
for my app on the typical setup either business or
domestic.

Thanks for that.
"Stephany Young" <noone@localhostwrote in message
news:u2**************@TK2MSFTNGP02.phx.gbl...
The earlier run was on a super grunty server with really fast scsi drives,
truckloads of ram and multiple dual-core perocessors.
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:OS**************@TK2MSFTNGP04.phx.gbl...
>Oh i see you mean you ran my code on your machine.

surely it can't be that fast

I have a 7200RPM 60GB drive in 1.86GHz Pentium M Laptop

What is your specs?
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:e6**************@TK2MSFTNGP04.phx.gbl...
>>Sorry Stephen what do you mean?

"Stephany Young" <noone@localhostwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
It was YOUR code!
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl. ..
Sorry about that , but it just a class with the generic list and a
string drive property
>
All I am doing is displaying some of the info when ScanFolder returns
But that is after the scan completes of course which is not the
problem.
>
Any chance of seeing your code???
>
public class DriveData
>
{
>
private List<PieFileInfomList = new List<PieFileInfo>();
>
public List<PieFileInfoDataList
>
{
>
get { return mList; }
>
set { mList = value; }
>
}
>
private string mDrive;
>
public string Drive
>
{
>
get { return mDrive; }
>
set { mDrive = value; }
>
}
>
}
>
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl.. .
>Approx. 13 seconds on a 250GB disk with 30,000+ directories and
>1,000,000+ files.
>>
>What is DriveData? (You omitted to post it).
>>
>What do you do with the content of DriveData when the call to
>ScanFolder(...) returns?
>>
>>
>>
>"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
>news:ei**************@TK2MSFTNGP04.phx.gbl. ..
>>OK. Here is the class the scans the drive.
>>>
>>Can you see any issues here?
>>>
>>Bela, would you be able to post your code that scans the drive.
>>>
>>I am scanning 56GB in about 10 minutes.
>>public struct PieFileInfo
>>>
>>{
>>>
>>public int RowID;
>>>
>>public PieInfoType Type;
>>>
>>public string Name;
>>>
>>public string FullName;
>>>
>>public double Filesize;
>>>
>>public DateTime LastAccess;
>>>
>>public DateTime Created;
>>>
>>public string Extension;
>>>
>>public DateTime LastWrite;
>>>
>>public int ParentFolderRowID;
>>>
>>public string Drive;
>>>
>>public double FileAge1;
>>>
>>public double FileAge2;
>>>
>>public double FileAge3;
>>>
>>public bool IsRoot;
>>>
>>}
>>>
>>public class ScanDrive
>>>
>>{
>>>
>>private DriveData mList = new DriveData();
>>>
>>public DriveData DataList
>>>
>>{
>>>
>>get { return mList; }
>>>
>>set { mList = value; }
>>>
>>}
>>>
>>private string mDrive;
>>>
>>private int mNewFolderID = 0;
>>>
>>public ScanDrive(string drivefolder)
>>>
>>{
>>>
>>mDrive = drivefolder;
>>>
>>mList.Drive = drivefolder;
>>>
>>}
>>>
>>public bool ScanFolder(string folder, int folderID, ref double
>>psize1, ref double psize2, ref double psize3)
>>>
>>{
>>>
>>DirectoryInfo objDir = new DirectoryInfo(folder);
>>>
>>int newFolderID;
>>>
>>double size1 = 0;
>>>
>>double size2 = 0;
>>>
>>double size3 = 0;
>>>
>>System.DateTime fileDate;
>>>
>>try
>>>
>>{
>>>
>>newFolderID = WriteRow(objDir, folderID);
>>>
>>if (newFolderID == 0)
>>>
>>{
>>>
>>return false;
>>>
>>}
>>>
>>foreach (DirectoryInfo dir in objDir.GetDirectories())
>>>
>>{
>>>
>>if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
>>psize3))
>>>
>>{
>>>
>>return true;
>>>
>>}
>>>
>>size1 += psize1;
>>>
>>size2 += psize2;
>>>
>>size3 += psize3;
>>>
>>}
>>>
>>foreach (FileInfo fle in objDir.GetFiles())
>>>
>>{
>>>
>>WriteRow(fle, newFolderID);
>>>
>>fileDate = GetAgeDate(fle);
>>>
>>if (fileDate >=
>>DateTime.Today.AddDays(Settings.Instance.Set tingsData.Age1Days
>>* -1))
>>>
>>size1 += fle.Length;
>>>
>>else if (fileDate >=
>>DateTime.Today.AddDays(Settings.Instance.Set tingsData.Age2Days
>>* -1))
>>>
>>size2 += fle.Length;
>>>
>>else
>>>
>>size3 += fle.Length;
>>>
>>}
>>>
>>UpdateFolderRow(newFolderID, size1, size2, size3);
>>>
>>psize1 = size1;
>>>
>>psize2 = size2;
>>>
>>psize3 = size3;
>>>
>>return true;
>>>
>>}
>>>
>>catch (Exception)
>>>
>>{
>>>
>>return true;
>>>
>>}
>>>
>>>
>>>
>>}
>>>
>>private DateTime GetAgeDate(FileInfo f)
>>>
>>{
>>>
>>if (f.CreationTime >=
>>DateTime.Today.AddDays(Settings.Instance.Set tingsData.Age1Days
>>* -1))
>>>
>>return f.CreationTime;
>>>
>>else if (f.LastWriteTime >=
>>DateTime.Today.AddDays(Settings.Instance.Set tingsData.Age2Days
>>* -1))
>>>
>>return f.LastWriteTime;
>>>
>>else
>>>
>>return f.LastAccessTime;
>>>
>>}
>>>
>>private int WriteRow(DirectoryInfo dir, int folderID)
>>>
>>{
>>>
>>PieFileInfo info = new PieFileInfo();
>>>
>>if (mNewFolderID == 0)
>>>
>>info.IsRoot = true;
>>>
>>mNewFolderID++;
>>>
>>info.RowID = mNewFolderID;
>>>
>>info.Type = PieInfoType.Folder;
>>>
>>info.FullName = dir.FullName;
>>>
>>info.Name = dir.Name;
>>>
>>info.LastAccess = dir.LastAccessTime;
>>>
>>info.LastWrite = dir.LastWriteTime;
>>>
>>info.Created = dir.CreationTime;
>>>
>>info.ParentFolderRowID = folderID;
>>>
>>info.Drive = mDrive;
>>>
>>mList.DataList.Add(info);
>>>
>>return mNewFolderID;
>>>
>>}
>>>
>>private int WriteRow(FileInfo file, int folderID)
>>>
>>{
>>>
>>PieFileInfo info = new PieFileInfo();
>>>
>>info.Type = PieInfoType.File;
>>>
>>info.Name = file.Name;
>>>
>>info.FullName = file.FullName;
>>>
>>info.Filesize = file.Length;
>>>
>>info.Extension = file.Extension;
>>>
>>info.LastAccess = file.LastAccessTime;
>>>
>>info.LastWrite = file.LastWriteTime;
>>>
>>info.Created = file.CreationTime;
>>>
>>info.ParentFolderRowID = folderID;
>>>
>>info.Drive = mDrive;
>>>
>>if (file.LastAccessTime >= DateTime.Today.AddDays(-30))
>>>
>>info.FileAge1 = file.Length;
>>>
>>else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))
>>>
>>info.FileAge2 = file.Length;
>>>
>>else
>>>
>>info.FileAge3 = file.Length;
>>>
>>mList.DataList.Add(info);
>>>
>>return folderID;
>>>
>>}
>>>
>>private void UpdateFolderRow(int folderID, double size1, double
>>size2, double size3)
>>>
>>{
>>>
>>int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)
>>>
>>{
>>>
>>if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)
>>>
>>return true;
>>>
>>else
>>>
>>return false;
>>>
>>});
>>>
>>PieFileInfo info = mList.DataList[index];
>>>
>>info.FileAge1 += size1;
>>>
>>info.FileAge2 += size2;
>>>
>>info.FileAge3 += size3;
>>>
>>info.Filesize += size1 + size2 + size3;
>>>
>>mList.DataList[index] = info;
>>>
>>}
>>>
>>}
>>>
>>>
>>>
>>"Bela Istok" <be****@hotmail.comwrote in message
>>news:ED**********************************@mi crosoft.com...
>>>What do you scan? I do a directory and File scan in my 100GB (64GB
>>>of data) hard drive and took 24 seconds. (Scanned every directory
>>>and every file in the drive for info).
>>>>
>>>PD: for reference 170,187 files and 21,899 folders.
>>>>
>>>>
>>>Regards,
>>>>
>>>Bela Istok
>>>>
>>>"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in
>>>message news:er**************@TK2MSFTNGP05.phx.gbl...
>>>>Hi,
>>>>>
>>>>I am writing an app that scans hard drives and logs info
>>>>about every fine on the drive.
>>>>>
>>>>The first iteration of my code used a class and a generic list
>>>>to store the data and rhis took 13min on my 60 GB drive.
>>>>>
>>>>I wanted it to be quicker.
>>>>>
>>>>So the second time I changed the class to a struct and still
>>>>with the generic list got the time down to 4 min.
>>>>>
>>>>I am wondering if I can improve on this even more??
>>>>>
>>>>Anyone know if it would be possible to improve this
>>>>using C# or would it need to be wrritten in assembler or the like?
>>>>>
>>>>rotsey
>>>>>
>>>>>
>>>>
>>>
>>>
>>
>
>


Oct 22 '07 #17
The first I see in you code is the use of Doubles, you don't need dobles you
only need long types for the size value.

You code run in 4 min. Going to see if can perform better.

Regards,

Bela Istok
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1, ref
double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@microsof t.com...
>What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and every
file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
>>Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey


Oct 22 '07 #18
Liz

Where is PieInfoType defined? do you have a driver stub which launches this
thing?
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1, ref
double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.SettingsD ata.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@microsof t.com...
>What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and every
file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
>>Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey



Oct 22 '07 #19
public enum PieInfoType
{
Folder,
File
}

Regards,

Bela Istok
"Liz" <li*@tiredofspam.comwrote in message
news:um**************@TK2MSFTNGP06.phx.gbl...
>
Where is PieInfoType defined? do you have a driver stub which launches
this thing?
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
>OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@microso ft.com...
>>What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and every
file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey


Oct 22 '07 #20
I redo the code (your code), using Delegates and get a first run of 4
minutes, and second and later run under a minute. (This is fine if you have
multi processor or multi core machine, with only 1 core you don't win much).
I will try to post the code later when have time to clean it a bit.

Regards,

Bela Istok
"Bela Istok" <be****@hotmail.comwrote in message
news:1B**********************************@microsof t.com...
The first I see in you code is the use of Doubles, you don't need dobles
you only need long types for the size value.

You code run in 4 min. Going to see if can perform better.

Regards,

Bela Istok
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
>OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Settings Data.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@microso ft.com...
>>What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and every
file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
Hi,

I am writing an app that scans hard drives and logs info
about every fine on the drive.

The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.

I wanted it to be quicker.

So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.

I am wondering if I can improve on this even more??

Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?

rotsey

Oct 22 '07 #21
Last run with code:
Using delegated function
Start time:10/22/2007 5:13:19 PM
End time:10/22/2007 5:16:58 PM
Total time:00:03:39.6027394
Size1: 769462539; Size2: 2074779247; Size3:52272046924; File Number:169593;
Directory Number:21854;

Code:
Attached.

Regard,

Bela Istok

"Bela Istok" <be****@hotmail.comwrote in message
news:FA**********************************@microsof t.com...
>I redo the code (your code), using Delegates and get a first run of 4
minutes, and second and later run under a minute. (This is fine if you have
multi processor or multi core machine, with only 1 core you don't win
much). I will try to post the code later when have time to clean it a bit.

Regards,

Bela Istok
"Bela Istok" <be****@hotmail.comwrote in message
news:1B**********************************@microsof t.com...
>The first I see in you code is the use of Doubles, you don't need dobles
you only need long types for the size value.

You code run in 4 min. Going to see if can perform better.

Regards,

Bela Istok
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
>>OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setting sData.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setting sData.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Setting sData.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Setting sData.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@micros oft.com...
What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and
every file in the drive for info).

PD: for reference 170,187 files and 21,899 folders.
Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
Hi,
>
I am writing an app that scans hard drives and logs info
about every fine on the drive.
>
The first iteration of my code used a class and a generic list
to store the data and rhis took 13min on my 60 GB drive.
>
I wanted it to be quicker.
>
So the second time I changed the class to a struct and still
with the generic list got the time down to 4 min.
>
I am wondering if I can improve on this even more??
>
Anyone know if it would be possible to improve this
using C# or would it need to be wrritten in assembler or the like?
>
rotsey
>
>
Oct 22 '07 #22
ok thanks Bela,

I will run it.

When you ran this code, the file system info is cached
so the second time your un it it is much faster because of this.

Were these stats from the first run????

"Bela Istok" <be****@hotmail.comwrote in message
news:6F**********************************@microsof t.com...
Last run with code:
Using delegated function
Start time:10/22/2007 5:13:19 PM
End time:10/22/2007 5:16:58 PM
Total time:00:03:39.6027394
Size1: 769462539; Size2: 2074779247; Size3:52272046924; File
Number:169593;
Directory Number:21854;

Code:
Attached.

Regard,

Bela Istok

"Bela Istok" <be****@hotmail.comwrote in message
news:FA**********************************@microsof t.com...
>>I redo the code (your code), using Delegates and get a first run of 4
minutes, and second and later run under a minute. (This is fine if you
have
multi processor or multi core machine, with only 1 core you don't win
much). I will try to post the code later when have time to clean it a bit.

Regards,

Bela Istok
"Bela Istok" <be****@hotmail.comwrote in message
news:1B**********************************@microso ft.com...
>>The first I see in you code is the use of Doubles, you don't need dobles
you only need long types for the size value.

You code run in 4 min. Going to see if can perform better.

Regards,

Bela Istok
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
OK. Here is the class the scans the drive.

Can you see any issues here?

Bela, would you be able to post your code that scans the drive.

I am scanning 56GB in about 10 minutes.
public struct PieFileInfo

{

public int RowID;

public PieInfoType Type;

public string Name;

public string FullName;

public double Filesize;

public DateTime LastAccess;

public DateTime Created;

public string Extension;

public DateTime LastWrite;

public int ParentFolderRowID;

public string Drive;

public double FileAge1;

public double FileAge2;

public double FileAge3;

public bool IsRoot;

}

public class ScanDrive

{

private DriveData mList = new DriveData();

public DriveData DataList

{

get { return mList; }

set { mList = value; }

}

private string mDrive;

private int mNewFolderID = 0;

public ScanDrive(string drivefolder)

{

mDrive = drivefolder;

mList.Drive = drivefolder;

}

public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)

{

DirectoryInfo objDir = new DirectoryInfo(folder);

int newFolderID;

double size1 = 0;

double size2 = 0;

double size3 = 0;

System.DateTime fileDate;

try

{

newFolderID = WriteRow(objDir, folderID);

if (newFolderID == 0)

{

return false;

}

foreach (DirectoryInfo dir in objDir.GetDirectories())

{

if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))

{

return true;

}

size1 += psize1;

size2 += psize2;

size3 += psize3;

}

foreach (FileInfo fle in objDir.GetFiles())

{

WriteRow(fle, newFolderID);

fileDate = GetAgeDate(fle);

if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settin gsData.Age1Days * -1))

size1 += fle.Length;

else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Settin gsData.Age2Days * -1))

size2 += fle.Length;

else

size3 += fle.Length;

}

UpdateFolderRow(newFolderID, size1, size2, size3);

psize1 = size1;

psize2 = size2;

psize3 = size3;

return true;

}

catch (Exception)

{

return true;

}

}

private DateTime GetAgeDate(FileInfo f)

{

if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Settin gsData.Age1Days * -1))

return f.CreationTime;

else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Settin gsData.Age2Days * -1))

return f.LastWriteTime;

else

return f.LastAccessTime;

}

private int WriteRow(DirectoryInfo dir, int folderID)

{

PieFileInfo info = new PieFileInfo();

if (mNewFolderID == 0)

info.IsRoot = true;

mNewFolderID++;

info.RowID = mNewFolderID;

info.Type = PieInfoType.Folder;

info.FullName = dir.FullName;

info.Name = dir.Name;

info.LastAccess = dir.LastAccessTime;

info.LastWrite = dir.LastWriteTime;

info.Created = dir.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

mList.DataList.Add(info);

return mNewFolderID;

}

private int WriteRow(FileInfo file, int folderID)

{

PieFileInfo info = new PieFileInfo();

info.Type = PieInfoType.File;

info.Name = file.Name;

info.FullName = file.FullName;

info.Filesize = file.Length;

info.Extension = file.Extension;

info.LastAccess = file.LastAccessTime;

info.LastWrite = file.LastWriteTime;

info.Created = file.CreationTime;

info.ParentFolderRowID = folderID;

info.Drive = mDrive;

if (file.LastAccessTime >= DateTime.Today.AddDays(-30))

info.FileAge1 = file.Length;

else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))

info.FileAge2 = file.Length;

else

info.FileAge3 = file.Length;

mList.DataList.Add(info);

return folderID;

}

private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)

{

int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)

{

if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)

return true;

else

return false;

});

PieFileInfo info = mList.DataList[index];

info.FileAge1 += size1;

info.FileAge2 += size2;

info.FileAge3 += size3;

info.Filesize += size1 + size2 + size3;

mList.DataList[index] = info;

}

}

"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@micro soft.com...
What do you scan? I do a directory and File scan in my 100GB (64GB of
data) hard drive and took 24 seconds. (Scanned every directory and
every file in the drive for info).
>
PD: for reference 170,187 files and 21,899 folders.
>
>
Regards,
>
Bela Istok
>
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl.. .
>Hi,
>>
>I am writing an app that scans hard drives and logs info
>about every fine on the drive.
>>
>The first iteration of my code used a class and a generic list
>to store the data and rhis took 13min on my 60 GB drive.
>>
>I wanted it to be quicker.
>>
>So the second time I changed the class to a struct and still
>with the generic list got the time down to 4 min.
>>
>I am wondering if I can improve on this even more??
>>
>Anyone know if it would be possible to improve this
>using C# or would it need to be wrritten in assembler or the like?
>>
>rotsey
>>
>>
>

Oct 23 '07 #23
The stats for the first run was the sended the other times takes < 30 sec.

Regards,

Bela Istok

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
ok thanks Bela,

I will run it.

When you ran this code, the file system info is cached
so the second time your un it it is much faster because of this.

Were these stats from the first run????

"Bela Istok" <be****@hotmail.comwrote in message
news:6F**********************************@microsof t.com...
>Last run with code:
Using delegated function
Start time:10/22/2007 5:13:19 PM
End time:10/22/2007 5:16:58 PM
Total time:00:03:39.6027394
Size1: 769462539; Size2: 2074779247; Size3:52272046924; File
Number:169593;
Directory Number:21854;

Code:
Attached.

Regard,

Bela Istok

"Bela Istok" <be****@hotmail.comwrote in message
news:FA**********************************@microso ft.com...
>>>I redo the code (your code), using Delegates and get a first run of 4
minutes, and second and later run under a minute. (This is fine if you
have
multi processor or multi core machine, with only 1 core you don't win
much). I will try to post the code later when have time to clean it a
bit.

Regards,

Bela Istok
"Bela Istok" <be****@hotmail.comwrote in message
news:1B**********************************@micros oft.com...
The first I see in you code is the use of Doubles, you don't need
dobles
you only need long types for the size value.

You code run in 4 min. Going to see if can perform better.

Regards,

Bela Istok
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
OK. Here is the class the scans the drive.
>
Can you see any issues here?
>
Bela, would you be able to post your code that scans the drive.
>
I am scanning 56GB in about 10 minutes.
public struct PieFileInfo
>
{
>
public int RowID;
>
public PieInfoType Type;
>
public string Name;
>
public string FullName;
>
public double Filesize;
>
public DateTime LastAccess;
>
public DateTime Created;
>
public string Extension;
>
public DateTime LastWrite;
>
public int ParentFolderRowID;
>
public string Drive;
>
public double FileAge1;
>
public double FileAge2;
>
public double FileAge3;
>
public bool IsRoot;
>
}
>
public class ScanDrive
>
{
>
private DriveData mList = new DriveData();
>
public DriveData DataList
>
{
>
get { return mList; }
>
set { mList = value; }
>
}
>
private string mDrive;
>
private int mNewFolderID = 0;
>
public ScanDrive(string drivefolder)
>
{
>
mDrive = drivefolder;
>
mList.Drive = drivefolder;
>
}
>
public bool ScanFolder(string folder, int folderID, ref double psize1,
ref double psize2, ref double psize3)
>
{
>
DirectoryInfo objDir = new DirectoryInfo(folder);
>
int newFolderID;
>
double size1 = 0;
>
double size2 = 0;
>
double size3 = 0;
>
System.DateTime fileDate;
>
try
>
{
>
newFolderID = WriteRow(objDir, folderID);
>
if (newFolderID == 0)
>
{
>
return false;
>
}
>
foreach (DirectoryInfo dir in objDir.GetDirectories())
>
{
>
if (!ScanFolder(dir.FullName, newFolderID, ref psize1,ref psize2,ref
psize3))
>
{
>
return true;
>
}
>
size1 += psize1;
>
size2 += psize2;
>
size3 += psize3;
>
}
>
foreach (FileInfo fle in objDir.GetFiles())
>
{
>
WriteRow(fle, newFolderID);
>
fileDate = GetAgeDate(fle);
>
if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age1Days * -1))
>
size1 += fle.Length;
>
else if (fileDate >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age2Days * -1))
>
size2 += fle.Length;
>
else
>
size3 += fle.Length;
>
}
>
UpdateFolderRow(newFolderID, size1, size2, size3);
>
psize1 = size1;
>
psize2 = size2;
>
psize3 = size3;
>
return true;
>
}
>
catch (Exception)
>
{
>
return true;
>
}
>
>
>
}
>
private DateTime GetAgeDate(FileInfo f)
>
{
>
if (f.CreationTime >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age1Days * -1))
>
return f.CreationTime;
>
else if (f.LastWriteTime >=
DateTime.Today.AddDays(Settings.Instance.Setti ngsData.Age2Days * -1))
>
return f.LastWriteTime;
>
else
>
return f.LastAccessTime;
>
}
>
private int WriteRow(DirectoryInfo dir, int folderID)
>
{
>
PieFileInfo info = new PieFileInfo();
>
if (mNewFolderID == 0)
>
info.IsRoot = true;
>
mNewFolderID++;
>
info.RowID = mNewFolderID;
>
info.Type = PieInfoType.Folder;
>
info.FullName = dir.FullName;
>
info.Name = dir.Name;
>
info.LastAccess = dir.LastAccessTime;
>
info.LastWrite = dir.LastWriteTime;
>
info.Created = dir.CreationTime;
>
info.ParentFolderRowID = folderID;
>
info.Drive = mDrive;
>
mList.DataList.Add(info);
>
return mNewFolderID;
>
}
>
private int WriteRow(FileInfo file, int folderID)
>
{
>
PieFileInfo info = new PieFileInfo();
>
info.Type = PieInfoType.File;
>
info.Name = file.Name;
>
info.FullName = file.FullName;
>
info.Filesize = file.Length;
>
info.Extension = file.Extension;
>
info.LastAccess = file.LastAccessTime;
>
info.LastWrite = file.LastWriteTime;
>
info.Created = file.CreationTime;
>
info.ParentFolderRowID = folderID;
>
info.Drive = mDrive;
>
if (file.LastAccessTime >= DateTime.Today.AddDays(-30))
>
info.FileAge1 = file.Length;
>
else if (file.LastAccessTime >= DateTime.Today.AddDays(-60))
>
info.FileAge2 = file.Length;
>
else
>
info.FileAge3 = file.Length;
>
mList.DataList.Add(info);
>
return folderID;
>
}
>
private void UpdateFolderRow(int folderID, double size1, double size2,
double size3)
>
{
>
int index = mList.DataList.FindIndex(delegate(PieFileInfo fi)
>
{
>
if (fi.Type == PieInfoType.Folder && fi.RowID == folderID)
>
return true;
>
else
>
return false;
>
});
>
PieFileInfo info = mList.DataList[index];
>
info.FileAge1 += size1;
>
info.FileAge2 += size2;
>
info.FileAge3 += size3;
>
info.Filesize += size1 + size2 + size3;
>
mList.DataList[index] = info;
>
}
>
}
>
>
>
"Bela Istok" <be****@hotmail.comwrote in message
news:ED**********************************@micr osoft.com...
>What do you scan? I do a directory and File scan in my 100GB (64GB of
>data) hard drive and took 24 seconds. (Scanned every directory and
>every file in the drive for info).
>>
>PD: for reference 170,187 files and 21,899 folders.
>>
>>
>Regards,
>>
>Bela Istok
>>
>"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
>news:er**************@TK2MSFTNGP05.phx.gbl. ..
>>Hi,
>>>
>>I am writing an app that scans hard drives and logs info
>>about every fine on the drive.
>>>
>>The first iteration of my code used a class and a generic list
>>to store the data and rhis took 13min on my 60 GB drive.
>>>
>>I wanted it to be quicker.
>>>
>>So the second time I changed the class to a struct and still
>>with the generic list got the time down to 4 min.
>>>
>>I am wondering if I can improve on this even more??
>>>
>>Anyone know if it would be possible to improve this
>>using C# or would it need to be wrritten in assembler or the like?
>>>
>>rotsey
>>>
>>>
>>
>
>


Oct 24 '07 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daniel | last post by:
when writing out a file from .net, when is the file created? after the bytes are all written to the hard drive or before the bytes are written to the hard drive?
8
by: Claudio Grondi | last post by:
It is maybe not a pure Python question, but I think it is the right newsgroup to ask for help, anyway. After connecting a drive to the system (via USB or IDE) I would like to be able to see...
0
by: Bruce W...1 | last post by:
I installed a new hard drive in my PC, setup Windows, Visual Studio, etc.. The old hard drive is now on IDE 2, and I will eventually be using it for backup. On the old hard drive are a few...
18
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra...
3
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard...
16
by: Otie | last post by:
Hi, Is there a way for VB5 to determine exactly where on a hard drive a .exe file is stored upon the .exe file's first copying to the hard drive? What I need to know is the exact hard drive...
6
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
2
by: =?Utf-8?B?Y29taXQy?= | last post by:
itried to install xp home edition . everything was loading ok untill eror message that os couldnot find hard disk drive. upon opening bios it shows my cd drive as primary and my dvd drive as...
1
by: =?Utf-8?B?c2hpZw==?= | last post by:
I have an old acer aspire 3610 hard drive that has some very important pictures on it, can someone please advise me as to what I need to get the pictures off the hard drive. Im aware that I will...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.