troubleshooting Question

rename file

Avatar of fwsteal
fwsteal asked on
.NET Programming
3 Comments1 Solution178 ViewsLast Modified:
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?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros