fwsteal
asked on
rename file
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(unixFil e)) return; //Error
File.Move(unixFile, unixfileRenamed);
}
//determine if the file exists
bool SourceFileExists(string myFile)
{
if (!System.IO.File.Exists(my File))
{
return false;
}
else
return true;
}
}
}
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
My error: An object reference is required for the nonstatic field, method, or property 'myLog_FileCopy.Program.So urceFileEx ists(strin g)'
How do I correct this error?
--------------------------
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
File.Move(winFile, winfileRenamed);
}
//rename unix log file
static void RenameUnixLog(string unixFile)
{
string unixfileRenamed = @"C:\Log\ua.txt";
if (!SourceFileExists(unixFil
File.Move(unixFile, unixfileRenamed);
}
//determine if the file exists
bool SourceFileExists(string myFile)
{
if (!System.IO.File.Exists(my
{
return false;
}
else
return true;
}
}
}
--------------------------
My error: An object reference is required for the nonstatic field, method, or property 'myLog_FileCopy.Program.So
How do I correct this error?
to be clear where to add it:
//determine if the file exists
static bool SourceFileExists(string myFile)
{
if (!System.IO.File.Exists(my File))
{
return false;
}
else
return true;
}
//determine if the file exists
static bool SourceFileExists(string myFile)
{
if (!System.IO.File.Exists(my
{
return false;
}
else
return true;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
add static before SourceFileExist
BCS