I have to search thru massive directory trees including all files within. I have one issue using the (Directory | DirectoryInfo | DirectoryInfo[] and the File | FileInfo | FileInfo[] )
They all mod the LastAccessedTime !!!! ANd the only property I need happens to this.... So if I look at it today and it was 10/5/1999 right after I look at it, it becomes DateTime.Now !! Grrrrrrr :)
I am probably overlopoking something simplistic but as it stands I need help fast.... Thanks in advance BillyDvd
========================= SAMPLE CODE ONLY ==========================
class Class1
{
MoreMethods DI = new MoreMethods();
List<FileInfos> ListToCompress = new List<FileInfos>();
DirectoryInfo RootDir = new DirectoryInfo( Variables.Root );
DirectoryInfo[ ] ROOT;
private void BtnGetDirectories_Click( object sender , EventArgs e )
{
ListToCompress = new List<FileInfos>();
ROOT = RootDir.GetDirectories( "*" , SearchOption.TopDirectoryO
nly );
foreach ( DirectoryInfo var in ROOT )
{
if ( DI.AddToList( var ) )
ListToCompress.Add( new FileInfos( var.FullName , var.LastAccessTime , var ) );
}
foreach ( FileInfos var in ListToCompress )
{
Console.WriteLine( var.Parent.ToString() + "\t" + var.LastAccessTime.ToStrin
g() + "\r\n" );
}
}
/// <summary>
/// Hold the relevant info for the list items
/// </summary>
internal class FileInfos
{
public DirectoryInfo Parent;
public string FullName;
public DateTime LastAccessedTime;
/// <summary>
/// Initializes a new instance of the <see cref="FileInfos"/> class.
/// </summary>
/// <param name="FullName">The full name.</param>
/// <param name="LastAccessedTime">Th
e last accessed time.</param>
/// <param name="Parent">The parent.</param>
public FileInfos( string FullName , DateTime LastAccessedTime , DirectoryInfo Parent )
{
this.FullName = FullName;
this.LastAccessedTime = LastAccessedTime;
this.Parent = Parent;
}
}
internal class MoreMethods
{
/// <summary>
/// Returns True if the item should be added to the list
/// </summary>
/// <param name="FileInfoArray"></par
am>
/// <returns></returns>
bool AddToList( FileInfo[ ] FileInfoArray )
{
if ( FileInfoArray.Length == 0 )
return false;
List<FileInfo> Addthesefiles = new List<FileInfo>( FileInfoArray );
//---| Lets see if there are any or all ready to be archived. |---
Addthesefiles = Addthesefiles.FindAll( IsOlderThan );
if ( Addthesefiles.Count == FileInfoArray.Length )
return true;
else
return false;
}
public bool AddToList( DirectoryInfo di )
{
DirectoryInfo[ ] da = di.GetDirectories( "*" , SearchOption.AllDirectorie
s );
if ( da.Length > 0 )
{
foreach ( DirectoryInfo var in da )
{
if ( !AddToList( var.GetFiles( "*" , SearchOption.AllDirectorie
s ) ) )
return false;
}
return true;
}
return AddToList( di.GetFiles( "*" , SearchOption.AllDirectorie
s ) );
}
}
}
Start Free Trial