I'm having problems with the c# code below.
-----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace myLog_FileCopy
{
class Program
{
static void Main(string[] args)
{
string winfile = @"C:\Log\alog.txt";
string unixfile = @"C:\Log\Ulog.txt";
//rename the files
RenameWinLog(winfile);
RenameUnixLog(unixfile);
}
//rename windows log file
static void RenameWinLog(string winFile)
{
string winfileRenamed = @"C:\Log\aw.txt";
if (!SourceFileExists(winFile)) return; //Error
File.Move(winFile, winfileRenamed);
}
//rename unix log file
static void RenameUnixLog(string unixFile)
{
string unixfileRenamed = @"C:\Log\ua.txt";
if (!SourceFileExists(unixFile)) return; //Error
File.Move(unixFile, unixfileRenamed);
}
//determine if the file exists
bool SourceFileExists(string myFile)
{
if (!System.IO.File.Exists(myFile))
{
return false;
}
else
return true;
}
}
}
-------------------------------------------------------------------------------------------------------------------
My error: An object reference is required for the nonstatic field, method, or property 'myLog_FileCopy.Program.SourceFileExists(string)'
How do I correct this error?
Our community of experts have been thoroughly vetted for their expertise and industry experience.