|
To compare the date modified you can simply use DirectoryInfo.LastWriteTime . To compare the size I am afraid you have to recursively go through directories and their subdirectories and sum up FileInfo.Length of contained files.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
There is now Explicit Method but try this.
There may are some mistakes because i wrote it without much testing.
private long FolderSize = 0;<br />
<br />
private bool comparefolders(string path1, string path2)<br />
{<br />
string strdate_path1 = string.Empty;<br />
string strdate_path2 = string.Empty;<br />
long foldersize1 = 0;<br />
long foldersize2=0;<br />
bool folders_compare = false;<br />
try<br />
{<br />
DirectoryInfo dirinfo_path1 = new DirectoryInfo(path1);<br />
DirectoryInfo dirinfo_path2 = new DirectoryInfo(path2);<br />
if (dirinfo_path1.Exists == true && dirinfo_path2.Exists == true)<br />
{<br />
strdate_path1 = dirinfo_path1.CreationTime.ToString();<br />
strdate_path2 = dirinfo_path2.CreationTime.ToString();<br />
foldersize1 = GetFolderSize(path1);<br />
foldersize2 = GetFolderSize(path2);<br />
if (foldersize1 == foldersize2 && strdate_path1 == strdate_path2)<br />
{<br />
folders_compare = true;<br />
}<br />
}<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
string error = ex.Message;<br />
}<br />
return folders_compare;<br />
}<br />
<br />
private long GetFolderSize(string Root)<br />
{<br />
FolderSize = 0;<br />
SeekFiles(Root);<br />
return FolderSize;<br />
} <br />
<br />
private void SeekFiles(string Root)<br />
{<br />
string[] Files = System.IO.Directory.GetFiles(Root);<br />
string[] Folders = System.IO.Directory.GetDirectories(Root); <br />
FileInfo File;<br />
for(int i=0;i<Files.Length-1;i++)<br />
{<br />
File = new FileInfo(Files[i]);<br />
FolderSize += File.Length;<br />
}<br />
<br />
for(int i=0; i< Folders.Length-1; i++)<br />
{<br />
SeekFiles(Folders[i]);<br />
} <br />
}
-- modified at 4:26 Friday 19th January, 2007
|
|
|
|
|
sir this is aravind here ,,i cant able to run the program,,if u can able to send full program(A-Z),,i am new to Dotnet,,,,,plz
|
|
|
|
|
Well, there are some additional considerations here:
- if you add a new file in one of the subdirectories, it does not change the last write time
of the top directory
- if you delete a file and create another with equal size, it does not alter total size.
So be careful about when you are satisfied nothing happened to a directory !
BTW: I am not sure about this, but the exact behavior could also depend on the underlying
file system (FAT, FAT32, NTFS, ...)
Luc Pattyn
|
|
|
|
|
Thats right but he only wanted an method two compare the size and the modify date of the folder and not of the files in it.
|
|
|
|
|
hi
i'm trying to set the location of a panel through my code.
how can i do this. is it done through the location property.
if yes then how do i manipulate this property??
regards
Saira
|
|
|
|
|
Example:
panel.Location = new Point(5, 5);
|
|
|
|
|
thank you
|
|
|
|
|
I have 2 forms:
1- Main form viewing a datagrid of different values of database X
2- A secondary form used for adding new data into database X
When any data is entered in Form2 and Form2 is closed; it's needed to update datagrid with new values in Form1. But it doesn't update quickly, a 3-4 second late. Using Access database, I've found a nasty dirty solution : Having a timer and updating datagrid periodically. Is this a problem about Access slow query time or any problem about forms or etc? Any idea ???
|
|
|
|
|
Hi, I'm working on an open source IDE that has a built-in syntax highlighter.
Right now, whenever I want to remove text from the RichTextBox, I have to do this:
<br />
RTB.Text = RTB.Text.Remove(CharacterIndex, RemoveAmount);<br />
The problem is that changing RTB.Text erases all the Rich Text Format information generated by the syntax highlighter.
So my question is, how do I remove text from the textbox without resetting the RTF data?
|
|
|
|
|
It does work!
Just pay attention to any ArgumentOutOfRangeException that is thrown when either your CharacterIndex or your RemoveAmount is less than zero.
SkyWalker
|
|
|
|
|
Hi,
I'm a intermediate java programmer and i just started learning C#.I would like to write an application that takes a txt file and send it to a fax machine. What is the best way I can do this? Thanks in advance ,any help would be gladly appreciated
|
|
|
|
|
wrote: I'm a intermediate java programmer and i just started learning C#
As a former Java developer myself, welcome to the wonderful world of C#.
Regarding your question, have you looked at any of the articles on this site? This article[^], for example, talks about how to fax an image. It shouldn't be too hard to figure out from there.
Also note that all file-related APIs are nice and organized in System.IO namespace (a "namespace" is like Java's "package"). For example, to read all text from a file, you can simply go System.IO.File.ReadAllText("theFile.txt");
|
|
|
|
|
thanks for the quick reply Judah, I will take a look into that article.
|
|
|
|
|
I get the following error when I try to send the fax.
com object with clsid{d73733c8-cc80-11d0-b225-00c04fb6c2f5} is either not valid or not registered
How do I reference to the faxcom lib?
|
|
|
|
|
Eddy, sounds like you'll need the FaxCom faxing object installed. (At least, that article uses that component.)
Does this post[^] help?
|
|
|
|
|
Thanks a lot Judah you are very helpful.
|
|
|
|
|
GEt a driver that faxes printed documents, and send it to the printer.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I'm trying to get some custom control on my MasterPage to happen on the click event on my menu control based on a SiteMap. It's never hitting the MenuItemClick code. Any ideas?
In master page:
<asp:label id="lblTest" runat="server" text="Test">
<asp:sitemapdatasource id="ExampleSiteMapDS" runat="server" showstartingnode="false" sitemapprovider="mySiteMapProvider">
<asp:menu id="Menu2" runat="server" datasourceid="ExampleSiteMapDS" onmenuitemclick="Menu2_MenuItemClick">
In master page cs:
protected void Menu2_MenuItemClick(Object sender, MenuEventArgs e)
{
lblTest.Text = e.Item.ValuePath;
}
Thanks, Jessica
|
|
|
|
|
I'm trying to get some custom control on my MasterPage to happen on the click event on my menu control based on a SiteMap. It's never hitting the MenuItemClick code. Any ideas?
In master page:
<asp:Label ID="lblTest" runat="server" Text="Test"></asp:Label>
<asp:SiteMapDataSource ID="ExampleSiteMapDS" runat="server" ShowStartingNode="false" SiteMapProvider="mySiteMapProvider" />
<asp:Menu ID="Menu2" runat="server" DataSourceID="ExampleSiteMapDS" OnMenuItemClick="Menu2_MenuItemClick" />
In master page cs:
protected void Menu2_MenuItemClick(Object sender, MenuEventArgs e)
{
lblTest.Text = e.Item.ValuePath;
}
Thanks, Jessica
|
|
|
|
|
|
"the page"?? The master page? If the menu items are on the page (I don't use a SiteMap), the page fires the click event. But I have to use a SiteMap.
Thanks, Jessica
|
|
|
|
|
Sorry, I should have been more clear. Each page needs to know the event exists on the master page.
|
|
|
|
|
Try this:
Click Edit MenuItem Databindings.
In the Menu DataBindings Editor, in the Available data bindings drop-down list, select SiteMapNode and click Add.
Select TextField in the Data binding properties drop-down list and select Title from the drop-down menu. Click OK.
Select the SiteMapDataSource control.
In Properties, set ShowStartingNode to False.
|
|
|
|
|
Thanks. That worked. It modified my aspx menu control by adding the databindings section.
<asp:menu id="Menu2" runat="server" datasourceid="ExampleSiteMapDS" onmenuitemclick="Menu2_MenuItemClick">
<databindings>
<asp:menuitembinding datamember="SiteMapNode" textfield="Title">
Thanks, Jessica
|
|
|
|