[MonoDevelop] Im learning to program and I'm getting an error i cant understand :(

Connel connelhooley at googlemail.com
Sun Apr 4 14:13:30 EDT 2010



Buttink wrote:
> 
> hmmmm............. can you put whats before that? I tried, but I cant
> recreate it.
> 

Yeah sure below is all my code. Just in case you need to know my GUI is made
up of two file chooser buttons (fchDestination and fchTarget) and a button
(btnSync). At the moment the program is just supposed to copy files from one
folder to another but only if the file does not exist in the other folder or
the file in the other folder is older. I am using OpenSuse 11.2 and
MonoDevelop 2.2. Thanks for the quick reply! Its really bugging me lol :)

using System;
using System.IO;
using Gtk;

public partial class MainWindow : Gtk.Window
{
	
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
	}

	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
	
	protected virtual void OnBtnSyncClicked (object sender, System.EventArgs e)
	{
		Sync(fchTarget.CurrentFolder);
	}
		
	protected void Sync (string strCurrentDirectory)
	{
		//string array of all the files in directory
		string[] staAllFiles = Directory.GetFiles(strCurrentDirectory);
				
		//loop over each file in directory
		foreach (string strFile in staAllFiles)
		{
			//string of just the files name and not its path
			string strFileName = Path.GetFileName(strFile);
												
			//tests if file does not exist in destination folder
			if (!File.Exists(fchDestination.CurrentFolder+strFileName)) {
				//if file does not exist copy it to destination folder, the true below
means overwrite if file already exists
				File.Copy (strFile, fchDestination.CurrentFolder+strFileName, true);
			}
			
			//tests if file does exist in destination folder
			if (File.Exists(fchDestination.CurrentFolder+strFileName)) {
				//long (number) that contains date of last write time of target file
				long lngTargetFileDate = File.GetLastWriteTime(strFile).ToFileTime();
				//long (number) that contains date of last write time of destination
file
				long lngDestinationFileDate =
File.GetLastWriteTime(fchDestination.CurrentFolder+strFileName).ToFileTime();
				
				//tests is target file is newer than destination file
				if (lngTargetFileDate > lngDestinationFileDate) {
					File.Copy (strFile, fchDestination.CurrentFolder+strFileName, true);
				}	
				//tests is target file is older than destination file
				if (lngTargetFileDate < lngDestinationFileDate) {
					File.Copy (strFile, fchTarget.CurrentFolder+strFileName, true);
				}
			}	
	
		}
			
	}
 }

-- 
View this message in context: http://n4.nabble.com/Im-learning-to-program-and-I-m-getting-an-error-i-cant-understand-tp1751009p1751039.html
Sent from the Mono - MonoDevelop IDE mailing list archive at Nabble.com.


More information about the Monodevelop-list mailing list